Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drop down box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have two forms which have two identical drop down boxes. The drop down boxes contains US states.

On form1 I have the following codes:
<select name=&quot;cboCountry&quot; size=&quot;1&quot;>
<% set rs = oConn.execute(&quot;select distinct State from tbl_Comp&quot;)
Do While not Rs.eof %>
<option value=&quot;<% =Rs(&quot;State&quot;)%>&quot;> </option>
<% Rs.movenext %>
<% Loop %>

On form2 I have the same loop. What I'd like to do is when the user chooses a state on form1, i.e. CA, the CA will appear on the drop down box on form2. Can you guys help?

Thanks.
 
That's going to be done with JavaScript. Go ahead and load this page onto your server and run it. It's a perfect example of how one list can set the second list to be the same value using a JavaScript loop. I've even put the second list into a different form. You might need to stare at it for a little bit to understand how it works. Let me know if you need further explanation.

Code:
<html>
<head>
<script Language=&quot;JavaScript&quot;>
<!--

function adjust2() {
  var list1value = document.form1.list1.options[document.form1.list1.selectedIndex].value
  for (var m = 0; m < document.form2.list2.length; m++) {
    if (document.form2.list2.options[m].value == list1value) {
      document.form2.list2.options[m].selected = true
    }
  }
}

//-->
</script>
</head>
<body>
<form name=&quot;form1&quot;>
<select name=&quot;list1&quot; onChange=&quot;adjust2();&quot;>
  <option value=&quot;CA&quot;>CA</option>
  <option value=&quot;TX&quot;>TX</option>
  <option value=&quot;NV&quot;>NV</option>
  <option value=&quot;WY&quot;>WY</option>
  <option value=&quot;OR&quot;>OR</option>
  <option value=&quot;NY&quot;>NY</option>          
</select> List #1 Changes List #2
</form>
<hr>
<form name=&quot;form2&quot;>
<select name=&quot;list2&quot;>
  <option value=&quot;CA&quot;>CA</option>
  <option value=&quot;TX&quot;>TX</option>
  <option value=&quot;NV&quot;>NV</option>
  <option value=&quot;WY&quot;>WY</option>
  <option value=&quot;OR&quot;>OR</option>
  <option value=&quot;NY&quot;>NY</option>          
</select> List #2
</form>
</body>
</html>

Whacky !! X-)

ToddWW
 
ToddWW,

I'm sorry I was unclear. I have the same drop down boxes on two web pages.

Thanks.
 
Oh, that's a little different story. X-)

On page 2, use this convention.

Code:
<select name=&quot;cboCountry&quot; size=&quot;1&quot;>
<%
dim m
dim k
k = Request.Form(&quot;cboCountry&quot;)
set rs = oConn.execute(&quot;select distinct State from tbl_Comp&quot;)
Do While not Rs.eof 
  m = &quot; &quot;
  IF Rs(&quot;State&quot;) = k THEN
    m = &quot; selected &quot;
  END IF
%>
<option<%=m%>value=&quot;<%=Rs(&quot;State&quot;)%>&quot;> </option>
<% 
  Rs.movenext
Loop
%>

That should do it. :)

ToddWW


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top