tmurray22
asked on
ASP form can't get rid of pulldown
I have an asp form with javascript. I changed the last field "city" to be check boces instead of a pulldown.
It works but the empty pulldown for "city" remains. If I take it out of the code, nothing works.
Here is the code.
<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strCountry, strRegion, strCity, objRS, strSelected
strCountry = Request.Form("Country")
strRegion = Request.Form("Region")
strCity = Request.Form("City")
'set connection strings for entire application
'strDataPath = server.MapPath("NorthWind. mdb")
strConnectString = "Provider=Microsoft.Jet.OL EDB.4.0; DATA SOURCE= "& Server.MapPath("fpdb\ptdb\ northwind. mdb")
if not IsObject("ojbConnection") then
set objConnection=Server.Creat eObject("A DODB.Conne ction")
objConnection.ConnectionTi meout = 15
objConnection.CommandTimeo ut = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
sub makeCountry()
if not isObject("objRS") then
set objRS=Server.CreateObject( "ADODB.Rec ordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Country FROM Customers ORDER BY Country",objConnection,3,3
Response.Write("<option></ option>" & VBCRLF )
do while not objRS.EOF
if objRS("Country") = strCountry then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Country") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub
sub makeRegion()
if strCountry <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject( "ADODB.Rec ordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Region FROM Customers WHERE Country = '" & strCountry & "' ORDER BY Region",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Regions Found</option>")
else
Response.Write("<option>Se lect Region Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Region") = strRegion then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Region") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Se lect a Country First</option>")
end if
end sub
sub makeCity()
if strRegion <> "Select a Country First" AND strRegion <> "Select Region Now" AND strRegion <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject( "ADODB.Rec ordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Cities Found</option>")
else
Response.Write("<option>Se lect City Now</option>" & VBCRLF )
%>
<div align="center">
<table border="1" width="18%" id="table1">
<tr>
<td width="97">
<%
do while not objRS.EOF
if objRS("City") = strCity then
strSelected = " Checked "
else
strSelected = ""
end if
%>
<tr><td><input type=checkbox name=City <%=strSelected%> value="<%=objRS("City")%>" ></td>
<td><%=objRS("City")%></td >
</tr>
<%
objRS.MoveNext
loop
end if%>
</table>
</div>
<%
objRS.Close
set objRS=Nothing
else
'Response.Write("<p>Select a Region First</p>")
end if
end sub
%>
<SCRIPT LANGUAGE=javascript>
<!--
function submitCountry(){
var objForm = document.forms[0];
objForm.elements['Region'] .selectedI ndex=0;
objForm.elements['City'].s electedInd ex = 0;
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['City'].s electedInd ex = 0;
objForm.submit();
}
function submitForm(){
var objForm = document.forms[0];
objForm.action = "http://www.FairfieldConsulting.com/processform.asp"
return true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<SELECT name="Country" onChange="submitCountry()" >
<%call makeCountry%>
</SELECT><br>
<SELECT name="Region" onChange="submitRegion()">
<%call makeRegion%>
</SELECT><br>
<SELECT name="City">
<%call makeCity%>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>
</HTML>
It works but the empty pulldown for "city" remains. If I take it out of the code, nothing works.
Here is the code.
<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strCountry, strRegion, strCity, objRS, strSelected
strCountry = Request.Form("Country")
strRegion = Request.Form("Region")
strCity = Request.Form("City")
'set connection strings for entire application
'strDataPath = server.MapPath("NorthWind.
strConnectString = "Provider=Microsoft.Jet.OL
if not IsObject("ojbConnection") then
set objConnection=Server.Creat
objConnection.ConnectionTi
objConnection.CommandTimeo
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
sub makeCountry()
if not isObject("objRS") then
set objRS=Server.CreateObject(
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Country FROM Customers ORDER BY Country",objConnection,3,3
Response.Write("<option></
do while not objRS.EOF
if objRS("Country") = strCountry then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Country") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub
sub makeRegion()
if strCountry <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject(
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Region FROM Customers WHERE Country = '" & strCountry & "' ORDER BY Region",objConnection,3,3
if objRS.eof then
Response.Write("<option>No
else
Response.Write("<option>Se
do while not objRS.EOF
if objRS("Region") = strRegion then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Region") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Se
end if
end sub
sub makeCity()
if strRegion <> "Select a Country First" AND strRegion <> "Select Region Now" AND strRegion <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject(
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
if objRS.eof then
Response.Write("<option>No
else
Response.Write("<option>Se
%>
<div align="center">
<table border="1" width="18%" id="table1">
<tr>
<td width="97">
<%
do while not objRS.EOF
if objRS("City") = strCity then
strSelected = " Checked "
else
strSelected = ""
end if
%>
<tr><td><input type=checkbox name=City <%=strSelected%> value="<%=objRS("City")%>"
<td><%=objRS("City")%></td
</tr>
<%
objRS.MoveNext
loop
end if%>
</table>
</div>
<%
objRS.Close
set objRS=Nothing
else
'Response.Write("<p>Select
end if
end sub
%>
<SCRIPT LANGUAGE=javascript>
<!--
function submitCountry(){
var objForm = document.forms[0];
objForm.elements['Region']
objForm.elements['City'].s
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['City'].s
objForm.submit();
}
function submitForm(){
var objForm = document.forms[0];
objForm.action = "http://www.FairfieldConsulting.com/processform.asp"
return true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<SELECT name="Country" onChange="submitCountry()"
<%call makeCountry%>
</SELECT><br>
<SELECT name="Region" onChange="submitRegion()">
<%call makeRegion%>
</SELECT><br>
<SELECT name="City">
<%call makeCity%>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No errors but now I cannot even select a region.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<%
sub makeCity()
if strRegion <> "Select a Country First" AND strRegion <> "Select Region Now" AND strRegion <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject(
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
if objRS.eof then
Response.Write("No Cities Found")
else
%><div align="center"><table border="1" width="18%" id="table1"><%
do while not objRS.EOF
if objRS("City") = strCity then
strSelected = " Checked "
end if
%>
<tr>
<td><input type=checkbox name=City <%=strSelected%> value="<%=objRS("City")%>"
<td><%=objRS("City")%></td
</tr>
<%
objRS.MoveNext
loop
end if
%></table></div><%
objRS.Close
set objRS=Nothing
else
Response.Write("<p>Select a Region First</p>")
end if
end sub
%>