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

Help! Select List value to be sent to SQL query

Status
Not open for further replies.

faithful1

Programmer
Sep 27, 2002
49
US
Hi,
I am trying to create a page that does a query on an sql database then stores those values in a select list. Once the user selects a value from that list, I want to query the same database with the value that was selected and display those on the same page.

So far, my first record set and population of the first select box looks as so:

<%
Dim RS
Dim RSChild
set RS = con.Execute (&quot;select&quot; _
& &quot; INDEX&quot; _
& &quot; ,NAME&quot; _
& &quot; ,URL&quot; _
& &quot; ,TARGET&quot; _
& &quot; ,OVERRIDE_SECURITY&quot; _
& &quot; ,PARENTID&quot; _
& &quot; ,ID&quot; _
& &quot; from DW.INTRAMENU MNU&quot; _
& &quot; INNER JOIN DW.INTRAMENULINKAGE LNK&quot; _
& &quot; ON MNU.INDEX = LNK.ID&quot; _
& &quot; WHERE PARENTID = 0&quot;)

%>

<Form Name=&quot;url&quot; target=&quot;url2.asp&quot; method=&quot;post&quot; OnLoad=(&quot;Children&quot;)>
<Select Name=&quot;Parent&quot; onChange=&quot;(Children)&quot;>
<OPTION value=1 SELECTED>None Selected</OPTION>
<%
Do until RS.EOF
%>
<OPTION VALUE=&quot;<%Response.write RS(&quot;ID&quot;)%>&quot;><%Response.write RS(&quot;NAME&quot;)%>
</OPTION>
<%
RS.MoveNext
Loop
%>
</SELECT>

Thanks!!!![ponder]

 
You cannot really add anything to a page after it has been sent to the browser. What you do is build the page with just the form the first time, then submit the form and build the page with the form plus the results the second time. To do that the script needs to determine whether it was requested by itself or not. The Request object has the answer to that.

Since you are going to build the form either way you could put this logic following the </SELECT>

Code:
 . . .
</SELECT>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;submit&quot; VALUE=&quot;All My Children&quot;>
</FORM>
<%
If Request(&quot;submit&quot;)= &quot;All My Children&quot; Then

While Not RSChild.EOF
%>

<any HTML you need to format results>
<%= RSChild.(&quot;Age&quot;) %>
<more HTML>

<%
Wend

End If
%>

By the way there are some errors in the HTML you posted
The form tag needs an ACTION attribute instead of a TARGET. The form is submitted to the ACTION, not the TARGET. TARGET is the name of a window not a URL.

<FORM> does use the onload event.

You could use the onchange event to run a Javascript function to submit the form. But remember Javascript is part of the HTML document, not part of your ASP script. At any rate the syntax would be

<SELECT NAME=&quot;Parent&quot; onChange=&quot;getChildren()&quot;>
 
Thanks a lot! Understanding the client side, server side is a little confusing at the moment. Just getting my feet wet, but thanks much for the response!!!![upsidedown]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top