So I'm not a JS guru by any means and I've spent the majority of the morning looking for an example of what I need and the only thing I can find that's close are the javascript examples where the arrays are hard coded.
What I need is two drop down boxes. One drop down box is hard coded with a list of users. The second drop down box should be populated based on the value of the user for the first. The first select would look like :
The values for my second drop down box would be retrieved from running a cgi script using a format similar to
Code:
virtual('/cgi-bin/script.cgi?id=001')
Currently my web page is php and the cgi script is perl which will generate php. I can change the script so it generates simply an array or list of strings or whatever, but what I don't know is javascript (or if php has a way to do this more easily) well enough to tie these things in together.
This is a common problem.
I made a search for populate select in the JavaScript section.
It returned a list of threads discussing this problem.
You can also check out QuirksMode for an article about poluating drop-down boxes under JavaScript->Forms->Dynamic options.
It uses JavaScript arrays to hold the data, not querying a server, but it should give you an idea on how to do it once you have the data.
You could also make the server regenerate the site when something is selected from the drop down list by using the onchange="" even of the selectbox and appending the value of the selected option to a querystring when reloading the page.
Or you could use AJAX, and only request the new data from the server. Then you won't have to update the whole page.
Sorry for giving so short explanations, but I've got a thing to take care of in a couple of minutes...
The three commented lines was something I was tinkering with, but I can't figure out how to do some what of a reverse lookup of the label based on the value.
Do you mean maintaining which user was selected during reload?
Why not append that info to the querystring too, and make the PHP code
insert a SELECTED attribute when printing out the options for the first box if the querystring is there?
Yes that's what I was thinking, I just thought I could do some sort of reverse lookup based on the value to determine the label and then create the the SELECTED line.