PDA

View Full Version : drop down dynamic value


sath
05-26-2003, 11:31 PM
i designed one interface for adding records. it has one textfield as new city and dropdown box as existing city.when form loads all existing cities are loaded to drop down box from the database. when user add new record if he add new city then he type name of the city in the textfield area.and drop down should be " none" value.if he add new record with existing one the text field should be empty and select existing city from the dropdown .now i want to change like when user type new city on the text filed the drop down could not load any thing from database it only have none.if the user do not type new city then only drop down sholud load existing city from database how to do it pls help me



the follwing is my code

rs.Open "Select distinct cityname from citytable order by cityname asc ",Conn

new city:<input name="city" type="TEXT" class="combo" style="height:16;width:130" size="20">

existing city:<select name="exist" style="height:16;width:130" class="combo" >
<option value="None">None</option>
<%while not rs.eof%>
<option value="<%=rs("cityname")%>"><%=rs("cityname")%></option>
<%rs.movenext%>
<%wend%>


pls any one have idea pls help me it is very urgent for me

amir
05-31-2003, 01:59 AM
you still "load" the values from the database and populate the dropdown with them, but you disable the dropdown.

this page is used to add a contact to the database. there is a fielf called organisation (org) wich could be a new one (not on the list . in the form i have a button that calles a javascript function wich disables the dropdown and enables a text feild to wich the user can write the new organization name.

<SCRIPT Lang="javascript">
function addneworg(){

if (document.all){
document.all.newone.disabled=!document.all.newone.disabled;
document.all.org.disabled=!document.all.org.disabled;
}
}
</script>

</HEAD>
<%
dim query
getorg = "select distinct Company from contacts"
set con = server.CreateObject("ADODB.Connection")
con.Open "provider = microsoft.jet.oledb.4.0; data source = c:\Inetpub\wwwroot\nic\controllers.mdb"
set orgRS = con.execute(getorg)
orga = orgRS.getrows()
set orgRS = nothing
%>
<BODY>

<CENTER><STRONG><FONT Color="darkorange" Size=4>Add Contacts</FONT></STRONG></CENTER>
<form Action="contact_add.asp" Method="post" Name="newcontact">
<table Border=1 BorderColor="steelblue"Align="center" >
<TR>
<th Align="center" BGColor="steelblue"><FONT Color="gold">Organization</FONT></th><td><select Size=1 Name="org">
<option Selected>- select organization - </OPTION>
<%for i = 0 to ubound(orga,2)%>
<OPTION><%=orga(0,i)%></OPTION>
<%next%>
<INPUT type="button" Value="Select / Add new" Name="chk" onclick="addneworg()">

<INPUT Type="text" Name="newone" Disabled>
</TR>

<tr><th BGColor="steelblue"><FONT Color="gold">Name</FONT></th><td><INPUT Name="name" Type="text"></TD></TR>
<tr><th BGColor="steelblue"><FONT Color="gold">Job Description</FONT></th><td><INPUT Name="job" Type="text"></TD></TR>
<tr><th BGColor="steelblue"><FONT Color="gold">Phone</FONT></TH><TD><input Name="phone" Type="text"></TD></TR>
<TR><TH BGColor="steelblue"><FONT Color="gold">Mobile</FONT></TH><td><input Name="mobile" Type="text"></TD></TR>
<tr><th BGColor="steelblue"><FONT Color="gold">E-Mail</FONT></TH><TD><input Name="email"></TD></TR>
<th BGColor="steelblue"><FONT Color="gold">Remarks</FONT></TH><td><input Type="text" Name="remarks"></TD></TR>
</TABLE>
<CENTER><br><input Type="submit" Value="Add Contact"></CENTER>
</FORM>
<Hr color="darkorange">
<%
org = request.Form("org")
job = request.Form("job")
name = request.Form("name")
phone = request.Form("phone")
mobile = request.Form("mobile")
email = request.Form("email")
remarks = request.Form("remarks")
if org = "" then
org = request.Form("newone")
if org = "" then
response.Write("please insert the organitation name or choose one from the list")
else
for i = 0 to ubound(orga,2)
if org = orga(0,i) then
response.Write("name is on the list")
response.Redirect("contact_add.asp")
end if
next
if phone <> "" or mobile <> "" then
set con = server.CreateObject("ADODB.Connection")
con.Open "provider = microsoft.jet.oledb.4.0; data source = c:\Inetpub\wwwroot\nic\controllers.mdb"
newrecord = "INSERT INTO contacts (Company,Description,Name,Telephone,Mobile,Email,Remarks) values('" & org & "'" & "," & "'" & job & "'" & "," & "'" & name & "'" & "," & "'" & phone & "'" & "," & "'" & mobile & "'" & "," & "'" & email & "'" & "," & "'" & remarks & "')"
con.execute(newrecord)
response.Write(newrecord)
end if
end if
else
if phone <> "" or mobile <> "" then
set con = server.CreateObject("ADODB.Connection")
con.Open "provider = microsoft.jet.oledb.4.0; data source = c:\Inetpub\wwwroot\nic\controllers.mdb"
newrecord = "INSERT INTO contacts (Company,Description,Name,Telephone,Mobile,Email,Remarks) values('" & org & "'" & "," & "'" & job & "'" & "," & "'" & name & "'" & "," & "'" & phone & "'" & "," & "'" & mobile & "'" & "," & "'" & email & "'" & "," & "'" & remarks & "')"
con.execute(newrecord)
response.Write(newrecord)
end if
end if
%>

</BODY>
</HTML>