Wrox Programmer Forums
|
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
 
Old December 29th, 2004, 06:06 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creative_eye
Default 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.

 
Old December 29th, 2004, 09:14 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

http://www.google.com/search?hl=en&l...ropdown+in+ASP -- Hope this would help you!

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old December 29th, 2004, 10:14 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

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>&nbsp;</P>

</BODY>
</HTML>


 
Old December 30th, 2004, 06:02 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creative_eye
Default

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.


 
Old December 30th, 2004, 08:31 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
 Do as follows..(Enclose that value in single Quotes).
<option value='<% =Rs.Fields("SNo")%>'><% =Rs.Fields("City")%></option>

 
Old December 31st, 2004, 02:39 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creative_eye
Default

and what about storing the value in a variable.
(the value of <Option value=?>

 
Old January 4th, 2005, 04:09 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
     i didnt get you. can u tell me what exactly you want..

 
Old January 11th, 2005, 06:17 AM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to creative_eye
Default

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>&nbsp;</p>
<input type=submit>
</form>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling a combo box w/in datagridview kscase Visual Basic 2005 Basics 1 July 12th, 2007 07:26 AM
FILLING COMBO BOXS WITH FOLDERS NAMES moony Classic ASP Professional 0 December 13th, 2005 09:04 AM
filling a combo box from a data object allee_man Beginning VB 6 1 March 1st, 2005 08:08 AM
Auto Filling Combo on Form penta Access 2 December 3rd, 2004 06:14 AM
filling a combo box using an array tware VB Databases Basics 0 September 21st, 2004 08:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.