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

Query with HTML variable

Status
Not open for further replies.

flnMichael

Programmer
Nov 13, 2003
96
US
Hey,
I want to perform a SQL Query after I have chosen an item through a drop down and have that variable chosen entered into the query. I want to do this all through the same page, no refresh, no new page. Here's what I have:


SQLQuery = "select distinct program from TP_Fact order by program"
Set rs4 = objdbConnection.Execute(SQLQuery)

....

<td>
<b>Program:</b>
<SELECT NAME="program" size="1" tabindex="5">
<option selected value='SELECT_TEST'>What Program?</option>
<%
Do While(rs4.EOF = FALSE)
Response.Write("<option>")
Response.Write(rs4.Fields("Program").value)
Response.Write("</option>")
rs4.MoveNext
Loop
Response.Write("</select></td>")
%>
</td>


SQLQuery = "select TP_Number,TP_Title from TP_Fact where program = ???"
Set rs5 = objdbConnection.Execute(SQLQuery)

??? chosen in the previous drop down. This is where I'm confused...can it be done, or do I have to at least refresh the page with the new value?

Thanks
Mike
 
Are you doing this in ASP? You can't do it in plain old HTML. If you want to run a query that uses data entered by a user then you need to POST the data to the ASP, run the query, generate the HTML and then send it back to the client. There are a couple of ways you can do this. You could have a static HTML page with a form that POSTs data to an ASP page. The ASP queries the request for the value of the select, runs the query, generates the page and sends back the response.

In short, if you want your pages to be dynamic based on decisions made by the client then you are going to need at least one round-trip.

Cheers, Max
 
Yep, the round trip is required. When the web page is first requested, the web server logs into the database server, gets the data, generates the web page and sends it to the client. At that point the web server and web browser assume that you are done, and will close the browser. You can change form elements all day long, but without submitting that data back to the web server there will be no way to process the returned data.

If you just want a single output to change on the web page based on the drop down, you can preload all the available options into javascript, and when the drop down menu is changed, the javascript is fired, and the page changed based on the javascript. But this is all client based, no new information is actually downloaded from the web server or database server, and nothing is based back to the web server. It also increases the download time of the web page as there is now much more info to download.

But doing the javascript approch does have it's up side. Once the page is loaded reaction time is much faster, as nothing has to be reprocessed by the web server. And if this is a corporate web page, then the download time won't really matter as everyone should be on the LAN.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
 
Thanks guys, I thought it was going to be that way, just figured there might have been something new I had missed. mrdenny you're right, it is on the LAN and so is everyone else, so the download time won't really matter that much. Thanks for the help

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top