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

SQL Statement inside JavaScript code in ASP page

Status
Not open for further replies.

pmcdaniel

Programmer
Feb 9, 2007
127
US
I have some radio buttons in an ASP web page and when I click on any of these buttons I'd like to display a list retrieved from a SQL statement.

I'm fairly new to this so for all I know there's another way to do it that I don't know about.

Right now I have a JavaScript routine called from the onClick event but I can't get the Classic ASP code to execute the SQL statement inside the routine to retrieve the list I want.

I would include the code but I've rewritten it so many times I know it's all messed up.

Is there a way to do this? If so how?

Thanks much.
 
JavaScript routine called from the onClick event but I can't get the Classic ASP code to execute the SQL statement

3 ways.

1. You can make the form for your web page submit when you click on the radio button and set a flag variable in your form. After the page reloads, do number 3 below on a conditional based on the flag value.

2. Look into AJAX.

3. Pull the info from the SQL statement into an array at the top of your page, then grab the info from the array when the radio button is clicked on.

[monkey][snake] <.
 
Also, as a future reminder (and part of what monksnake's post was trying to say) is that you cannot do what you are trying to do as you've laid it out. There are alternatives (such as monksnake has indicated), but you have to alter how you've created your page so far.

You cannot mix server-side and client-side code. Your javascript, in this instance, is client-side code. By the time you are ready to click on a button and run your client-side code, the server-side code (the ASP, in this case) has already run and returned everything to the client. If you wish to make a call and retrieve data from SQL server, you will either need to submit your page and carry out actions from there or have the data already available (because you retrieved it when you first opened the page) and then process from there.

If you have additional questions, feel free to ask.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Thanks monksnake & Chopstik. Chopstik, thanks again for explaining it all better.

I actually thought I'd have to have the results and hide them till needed but then the page would take longer to load. I was hoping there'd be another way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top