 |
| ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 29th, 2004, 06:06 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Filling combo on selection
I'm trying to populate a combo on the selection of another combo box.
The scenario is, there are two combo boxes on a form. First one shows the cities and other shows the Town names of that city. So i want when i select the city from first combo, page refresh and fill the second combo with the town names of that particular city.
Please guide me in this.
|
|

December 29th, 2004, 09:14 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

December 29th, 2004, 10:14 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Here I hard coded values for combobox.If you want you can get those values from database.
Depending n the value selected from 1st combo i am displyiing the values from Databse into the 2nd Combo.
Hope this helps you.
Thanks
Suresh
-------------------------------------------------------------
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script>
function doSubmit()
{
document.fSelect.action = "test.asp"
document.fSelect.method ="post"
document.fSelect.submit();
}
</script>
</HEAD>
<form name=fSelect action=test.asp method=post>
<select name=Town onchange="doSubmit()">
<option value=0>select</option>
<option value=1>HYD</option>
<option value=2>Calcutta</option>
<option value=3>Madras</option>
</select>
<%
If Request.Form("Town") > 0 Then
'Here open connection with following query. suppose objRs is the recordset name.
strSQl= "select * from Towns where city=" & Request.Form("Town")
End If
%>
<select name=City>
<%
If objRs.recordcount > 0 Then
While not objRs.eof%>
<option value=<%=objRs(0)%>><%=objRs(1)%></option>
<%objRs.movenext
wend
End If
%>
</select>
</form>
<body>
<P> </P>
</BODY>
</HTML>
|
|

December 30th, 2004, 06:02 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx both of you. Well, I want to get the "SNo" of the city too in the value <option value= >. Here is the code:
<option value=<% =Rs.Fields("SNo")%>><% =Rs.Fields("City")%></option>.
Now here how can i store the SNo in any variable?
One more problem is there, thats on another form. When i select any town from the combo list such as "Wapda Town" and submit the page, the value only transfer on the next page is "Wapda", and the "Town" is not transfere.
|
|

December 30th, 2004, 08:31 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Do as follows..(Enclose that value in single Quotes).
<option value='<% =Rs.Fields("SNo")%>'><% =Rs.Fields("City")%></option>
|
|

December 31st, 2004, 02:39 PM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
and what about storing the value in a variable.
(the value of <Option value=?>
|
|

January 4th, 2005, 04:09 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
i didnt get you. can u tell me what exactly you want..
|
|

January 11th, 2005, 06:17 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have written the following code. When the page loads, the first combo fills with the name of cities in the order wich is in the DB. When i select any city from the first combo, page goes refresh and the second combo fills with the Towns relating that particular city. But the problem is that everytime i select city it displays the first value as it is in the Db. And the second combo fills with the values (town names) related to the first value.
<script>
function doSubmit()
{
document.fSelect.action = "combo.asp"
document.fSelect.method ="post"
document.fSelect.submit();
}
</script>
</head>
<body>
<%
set con = Server.CreateObject("ADODB.Connection")
set Rs = Server.CreateObject("ADODB.Recordset")
Con.Open strConnect
SQL = "Select * FROM City"
Rs.Open SQL, Con, 1, 2
%>
<form name="fSelect" method="post" action="comboResult.asp">
<p> city
<select name="City" id="city" onchange="doSubmit()">
<% While Not Rs.EOF %>
<option value= <% = Rs.Fields("SNo")%>><% =Rs.Fields("City")%></option>
<%
Rs.MoveNext
Wend
%>
</select>
</p>
<%
If Request.Form("City") > 0 Then
strSQl= "select * from Towns where SNo=SNo"
Rs.close
Rs.open strsql, con
End If
%>
<p>town
<select name="town" id="town">
<% If Rs.RecordCount > 0 Then
While Not Rs.EOF %>
<option value=<% =Rs.Fields("Towns")%>><% =Rs.Fields("Towns")%></option>
<% Rs.Movenext
Wend
End if
%>
</select>
</p>
<p> </p>
<input type=submit>
</form>
|
|
 |