Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Using 1 Combo Box to Populate Another
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

paulnoe
Starting Member

USA
48 Posts

Posted - 19 January 2005 :  16:01:08  Show Profile  Visit paulnoe's Homepage
I have a date range and two combo boxes on a form. The first combo box is simple - select either S or C.

If the user selects "S", then populate the second combo box based on query A. If the user selects "C", then populate the second combo box based on query B.

I tried refreshing the page and trying to pass the value back through a querystring but no dice. I'm sure there's a better way, but I can't find it anywhere. Any ideas? FYI, I'm using VBScript/ASP3.0

Thanks for your time!
Paul

Paul Noe
paul@thenoes.com

Classicmotorcycling
Development Team Leader

Australia
2084 Posts

Posted - 19 January 2005 :  16:55:51  Show Profile
What it looks like you would be looking for, would be something like this:

refresh page????

You just need to to ajust it to suit your needs, but puts you on the right direction.

This message brought to you by: Search is your friend

Cheers,

David Greening
Go to Top of Page

Classicmotorcycling
Development Team Leader

Australia
2084 Posts

Posted - 19 January 2005 :  17:27:18  Show Profile
I have done some playing with the code and got this for you:
<html>
<head>
<script type="text/javascript">
function changeselect(va,el){
var arrValue,arrDisplay;
arrValue=new Array();
arrDisplay=new Array();
arrValue[0]=[];
arrDisplay[0]=[""];
arrValue[1]=[0,1,2];
arrDisplay[1]=["zero","one","two"];
arrValue[2]=[3,4,5];
arrDisplay[2]=["three","four","five"];
if(va!=""){
document.getElementById(el).options.length=0;
for(var x=0;x<arrValue[va].length;x++){
document.getElementById(el)[x]=new Option(arrDisplay[va][x],arrValue[va][x]);
}
}
}
</script>
</head>
<body>
<select size="1" name="D0" onchange="changeselect(this.options[this.selectedIndex].value,'D1');">
	<option value="">Select</option>
	<option value="1">S</option>
	<option value="2">C</option>
</select>
<p>
<%
if arrValue = 0 then %>
<select size="1" name="D1" id="D1">
	<option value=""></option>
</select>
<% else %>
<select size="1" name="D1" id="D1">
	<option value="0">zero</option>
	<option value="1" >one</option>
	<option value="2">two</option>
	<option value="3">three</option>
	<option value="4">four</option>
	<option value="5">five</option>
</select>
<% end if %>
</body>
<html>
I hope it helps.

Cheers,

David Greening
Go to Top of Page

paulnoe
Starting Member

USA
48 Posts

Posted - 20 January 2005 :  09:32:37  Show Profile  Visit paulnoe's Homepage
David,

Thank you very much for your time in monkeying with the code. I'll give it a shot today and see how it goes. I'll report back - Thanks a million -

Paul

Paul Noe
paul@thenoes.com
Go to Top of Page

paulnoe
Starting Member

USA
48 Posts

Posted - 20 January 2005 :  13:49:20  Show Profile  Visit paulnoe's Homepage
That code worked perfectly for populating based on the hard-coded arrays in the header js function. Is there a way to simply assign a variable in the changeselect procedure and use it in an if-then block later on in the page? I added this code:

var strCompanyType=0;
strCompanyType=va;

to the function, then tried to use that variable here:

<%
If strCompanyType = 0 then
%>
<tr>
<td ALIGN="right">Select a Location:</td>
<td ALIGN="left" valign="middle">  
<select size="1" name="D1" id="D1">
<option value=""></option>
</select>
</td>
<td></td></tr>
<%
Else
%>
<tr>
<td ALIGN="right">Select a Location:</td>
<td ALIGN="left" valign="middle">  
<select size="1" name="D1" id="D1">
<option value="0">Please Select</option>
<option value="1">Legit Choice 1</option>
</select>
</td>
<td></td></tr>
<%
end if
%>

And got a variable undefinied error. Should I just populate the arrays in the function with the two different recordsets for the second combo box? One other general question: When you use a javascript command like "onchange" can you call a function written in VB Script as well as Javascript?

Thanks again for your time.


Paul Noe
paul@thenoes.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07