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

Select Box Element as SQL parameter

Status
Not open for further replies.

Moonpie10

Programmer
Joined
Feb 22, 2005
Messages
14
Location
US
Hi,
I have gotten some great help from here before and I am hoping I can get some more. I have a jsp page with 3 select boxes with both the 2nd and 3rd boxes dependent on the first. I have gotten the 2nd box to work using an array and the onchange event, but the 3rd box is giving me fits! Based on what is chosen in the 1st box, I need that selection to use as a parameter in my sql query. If I query the database on page load and create an array, how would I, in javascript, only select from the array where the it meets the selection in the 1st box? Is there another way to do this? Any suggestions are appreciated.
 
could you show sample data for the three selects? i'm not sure what you mean by
how would I, in javascript, only select from the array where the it meets the selection in the 1st box?

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
the 1st box is region: USA, Canada

If 1st box = USA then
the 2nd box (the states are stored in an array): CA, UT, etc

if 1st box = USA then
the 3rd box should contain what is stored in the database already for that region ie., NC, PA. For the 3rd box the data is stored as: ID, Region, State so I could run a query on page load to grab everything out of the database by id, but an id could have multiple regions so I need to get the region USA ONLY if that is what is selected in the first box. I hope this makes sense.
 
Why don't you just have an onchange event in each of the first two select boxes that reloads the page, therefore causing the page to requery the database, populating the third select box.

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That was easy to do for the second box because I only have 7 regions so I could break them into 7 separate arrays. But with states and countries there are many more so rather then create all of those arrays I thought that if I could query the database based on the region selected in the first box...but I can't figure out how to grab what is selected in the first box and plug it into my sql query
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top