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!

Certainly Not an FAQ - List Box problem - F1 please. 2

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hi..
This might sound like an FAQ, but it isn't.

I have 2 list boxes. The first one ISN'T dynamic, but the second one is. It gets the value from a Table.

Now, All the ASP sites and FAQs that deal with Double List Box talks about

* Both list boxes being static/hard-coded OR
* Both list boxes being dynamic/fetched from the table.


My case is different. I need to have 1 static and 1 dynamic list box.

Depending on the selection made in first box, We got to refresh the second list box.

How to accomplish this mission ? Thank you...
RR

 
U have to resubmit the new querry to your original asp witch generated your first two lists boxes and the asp will generate a new dinamic list box

somehtmlfile.htm

<form name=&quot;fList&quot; id=&quot;fList&quot; action=&quot;proces.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;querry&quot; id=&quot;querry&quot; value=&quot;&quot;>
</form>

<SELECT NAME=&quot;list1&quot; onchange=&quot;doMySubmit(this)&quot;>
...
</SELECT>

<SELECT NAME=&quot;list2&quot;> this is dimamic generated
...
</SELECT>

<script language=&quot;javascript&quot;>
function doMySubmit(elem)
{
document.all.querry.value=elem.value;
document.all.fList.Submit();
};
</script>

proces.asp
<%
query=Request.Form(&quot;querry&quot;)
'search in database for querry
%>
<form name=&quot;fList&quot; id=&quot;fList&quot; action=&quot;proces.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;querry&quot; id=&quot;querry&quot; value=&quot;&quot;>
</form>
<!-- Here is the static list -->
<SELECT NAME=&quot;list1&quot; onchange=&quot;doMySubmit(this)&quot;>
...
</SELECT>
<!-- Here is the dinamic list -->
<SELECT NAME=&quot;list2&quot; onchange=&quot;doMySubmit(this)&quot;>
<%
while Not MyRecordset.Eof
%>
<OPTION><%=MyRecordset(&quot;MyDatabaseField&quot;)%>
<%
MyRecordset.MoveNext
wend
%>
</select>
<script language=&quot;javascript&quot;>
function doMySubmit(elem)
{
document.all.querry.value=elem.value;
document.all.fList.Submit();
};
</script>

proces.asp generate an html like the somehtmlfile.htm

Hope this could help u
 
You will want to post a form back to the same asp page that holds the static dropdown.

1. In that form your static dropdown will do a submit in the onChange event, calling a javascript function that actually submits the form.

2. Then catch the value of the static dropdown that was passed and do a select on the table that fills the dynamic dropdown based on the value passed from the static dropdown.

Below is the code:
'****************************************************
If Request.ServerVariables(&quot;CONTENT_LENGTH&quot;) > 0 Then

'Page goes here when form submitted
If Request.Form(&quot;select_1&quot;) = Variable_1 Then
strSQL = &quot;Select * from tblTableName where id = 1
elseif Request.Form(&quot;select_1&quot;) = Variable_2 Then
strSQL = &quot;Select * from tblTableName where id = 2
End If
rs.Open strSQL, data, adOpenForwardOnly, adLockOptimistic

<form action=Request.ServerVariables (&quot;SCRIPT_NAME&quot; method=POST id=form1 name=form1>

<select name=select_1 size=1 onChange=Form_Submit>
If Request.Form(&quot;select_1&quot;) = value_1 Then
<option value=value_1 SELECTED>Option_1</option>
Else
<option value=value_1>Option_1</option>
End If

If Request.Form(&quot;select_1&quot;) = value_2 Then
<option value=value_2 SELECTED>Option_2</option>
Else
<option value=value_2>Option_2</option>
End If
</select>

'**Dynamic Dropdown**
<select name=select_2 size=1>
Do While Not rs.EOF
<option value=&quot; & rs(&quot;OptionValue&quot;) & &quot;>&quot; & rs (&quot;OptionName&quot;) & &quot;</option>&quot;
rs.MoveNext
Loop
</select>

</form>


Else

'Page opens here first
strSQL = &quot;Select * from tblTableName
rs.Open strSQL, data, adOpenForwardOnly, adLockOptimistic

<form action=Request.ServerVariables(&quot;SCRIPT_NAME&quot;) method=POST id=form1 name=form1>

'**Static Dropdown**
<select name=select_1 size=1 onChange=Form_Submit>
<option value=value_1>Option_1</option>
<option value=value_2>Option_2</option>
</select>

'**Dynamic Dropdown**
<select name=select_2 size=1>
Do While Not rs.EOF
<option value=&quot; & rs(&quot;OptionValue&quot;) & &quot;>&quot; & rs (&quot;OptionName&quot;) & &quot;</option>&quot;
rs.MoveNext
Loop
</select>

</form>
 
Hello BarkingFrog,


What if I already have a form in that page ? I need to submit that too but not along with this... How can I submit this list box part alone ?



Thank you...
RR

 
Keep your dropdowns in a seperate form. Then when you call the javascript only submit the form with the dropdowns:

In your header you have the following:

<head>
<!--
<script language=javascript>
function Form_Submit() {

document.form1.submit();

}
</script>
-->
</head>

Place your other form wherever you want it and submit it when you are ready. I would assume that you will be submitting it after you choose the values in the dropdowns, so put it here:

If Request.ServerVariables(&quot;CONTENT_LENGTH&quot;) > 0 Then

'Page goes here when form submitted
If Request.Form(&quot;select_1&quot;) = Variable_1 Then
strSQL = &quot;Select * from tblTableName where id = 1
elseif Request.Form(&quot;select_1&quot;) = Variable_2 Then
strSQL = &quot;Select * from tblTableName where id = 2
End If
rs.Open strSQL, data, adOpenForwardOnly, adLockOptimistic

<form action=Request.ServerVariables (&quot;SCRIPT_NAME&quot; method=POST id=form1 name=form1>

<select name=select_1 size=1 onChange=Form_Submit>
If Request.Form(&quot;select_1&quot;) = value_1 Then
<option value=value_1 SELECTED>Option_1</option>
Else
<option value=value_1>Option_1</option>
End If

If Request.Form(&quot;select_1&quot;) = value_2 Then
<option value=value_2 SELECTED>Option_2</option>
Else
<option value=value_2>Option_2</option>
End If
</select>

'**Dynamic Dropdown**
<select name=select_2 size=1>
Do While Not rs.EOF
<option value=&quot; & rs(&quot;OptionValue&quot;) & &quot;>&quot; & rs (&quot;OptionName&quot;) & &quot;</option>&quot;
rs.MoveNext
Loop
</select>

</form>


FORM YOU ALREADY HAVE GOES HERE!!!!


other code continues here....

In addition, you can put hidden fields in your original form that can be populated using the same javascript function with the values of the dropdowns if you need to be able to submit those values as well when you do decide to submit your original form.

Hope this is clear. Let me know if it isn't.

:)
 
I got confused now.. Which to paste where ? But as it is, if I have a single form only, your code works extremely well..

And please note that this is an intranet task and hence, Client side VBScript is Ok. Thank you...
RR

 
U have to put the new listbox in other form with other name and id and use Request(&quot;FormName&quot;).(&quot;listboxname&quot;)
or Request(&quot;FormName&quot;)(&quot;listboxname&quot;)
See if it work...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top