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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reflecting a 2nd select box based on the option chosen for the 1st

Status
Not open for further replies.

neetu

Programmer
May 25, 2001
11
IN
hi if anyone could help me it would be great
i hv an asp page which has a combo box
depending on the options chosen in the combo box ....it should refresh or reload the page & display another combo box by the side of it with a set of values

ex:
the 1st combo box values could be
1.fruits
2.vegetables
3.drinks

the 2nd combo box value depending on the 1st one could be
for fruits :
1.apple
2.grapes
3.banana

for vegge :
1.carrot
2.radish
3.beetroot

for drinks :
1.coke
2.pepsi
3.tea

& so on

iam using asp for this & depending on the option chosen in the 1st combo box....i call onchange in it & in the javascript code ...i think i can use window.location & reload the page but how i do this retaining the old values & accepting new values

if u can help me with this itll be great
thnx


 
Here is an example...

-------select.asp file----------

Code:
<%@ Language=VBScript %>
<%
sel1_values=Array(&quot;None&quot;,&quot;Fruits&quot;,&quot;Vegetables&quot;,&quot;Drinks&quot;)
dim sel2_values(2,2)
sel2_values(0,0) =&quot;apple&quot;
sel2_values(0,1) =&quot;grapes&quot;
sel2_values(0,2)=&quot;banana&quot;

sel2_values(1,0) =&quot;carrot&quot;
sel2_values(1,1) =&quot;radish&quot;
sel2_values(1,2) =&quot;beetroot&quot;

sel2_values(2,0) =&quot;coke&quot;
sel2_values(2,1) =&quot;pepsi&quot;
sel2_values(2,2) =&quot;tea&quot;



sel1=Request(&quot;sel1&quot;)
if sel1=&quot;&quot; then sel1=&quot;None&quot;
%>
<HTML>
<BODY>
<form action=&quot;select.asp&quot; method=post name=frm id=frm>
Chose an Domain:
<select name=&quot;sel1&quot; id=&quot;sel1&quot; onchange=&quot;frm.submit();&quot;>
<%
for i=0 to Ubound(sel1_values)
%>
	<option value=&quot;<%=sel1_values(i)%>&quot;
<%if sel1=sel1_values(i) then%>selected<%
poz=i-1
end if%>><%=sel1_values(i)%>
<%
next
%>
</SELECT>
<br>
Options:
<select>
<%
if sel1<>&quot;None&quot; then
for i=0 to 2
%>
	<option value=&quot;<%=sel2_values(poz,i)%>&quot;><%=sel2_values(poz,i)%>
<%
next
end if
%>
</SELECT>
</form>
</BODY>
</HTML>
________
George, M
 
thnx a lot for the help Mr George M (Shadow)
All that seems fine .....

but there is a hitch i think in this.

in this case the 1st combo box has only 4 items init, but if it has around 30 items, & the 2nd combo box would have atleast 10 items on it depending on the chosen 1st item....
then do i still need to declare it through an array...i thought i could do it through a database...
i mean hv a database for the 1st combo box items along with the 2nd combobox items & then read it form that & do accordingly.

but here if i hv already given post action to the same form
i.e
<form action=&quot;select.asp&quot; method=post name=frm id=frm>
Chose an Domain:
<select name=&quot;sel1&quot; id=&quot;sel1&quot; onchange=&quot;frm.submit();&quot;>

& i need to hv another posting action form to submit all the data into another database.
<form action=&quot;database_submit.asp&quot; method=post name=frm>

here i dont think i can hv the form submitted to the database ....
so the problem is
1. i need to reload the form without losing through info.
2. i need to submit it to the database also.

or is there any other way to reload the form ..i mean by using window.location()

thnx for any help
neetu

 
Submit your form in the onblur event of the first combo.
In the asp if the user select fruit (value 1) you have to create a recordset wich contains only the fruits.
Use this recordset to create the second select.
If you want to submit your form (without making the new select list) you can submit it to another page or set a hidden value to something picked up by the asp. You can do this using the following java client script:

<script>
function newList() {
document.myform.status.value = &quot;makelist&quot;;
document.myform.action = &quot;someasp.asp&quot;;
document.myform.submit();
}

function mySubmit() {
document.myform.status.value = &quot;submit&quot;;
document.myform.action = &quot;someasp.asp&quot;;
document.myform.submit();
}
</script>
<FORM name=myform>
<input type=hidden name=status value='makelist'>
<SELECT name='department' size=10 onBlur=newList();>
<OPTION VALUE=106>Business & Financial Accounting</OPTION>
<OPTION VALUE=14>Business Development & Marketing</OPTION>
<OPTION VALUE=12>Canteen</OPTION>
<OPTION VALUE=13>Corporate Practice</OPTION>
<OPTION VALUE=108>Corporate Practice / Partnership Management</OPTION>
</SELECT>
<input type=button onClick=mySubmit();>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top