View Full Version : Need Help Scripting A Form Together

06-16-2007, 06:33 AM
Hi, I need help trying to tie together an idea of mine that involves multiple select boxes. It works basically identically to the way eBay allows sellers to choose a category for their item by narrowing down their item with multiple select boxes.

My multiple select box looks like this, so far:

<select multiple="multiple"><option>Option1</option><option>Option2</option></select>

Ideally, there will be three of these. The trick I need help with is:

a) making it so it's not really a *multiple* select box, but still looks like one. I want the user to see the options in the multi-line format as-is, but I only want them to be able to pick one at a time.
b) when an option is selected, the subsequent multiple select box is enabled and loaded with the data of the selection (a subset). The data of the second box is determined by the selection in the first box. This box will not be enabled or populated until a selection is made.
c) a way to obtain the information from a file stored on the directory. The info in this file will be the contents of the select box.

Thanks for any assistance.

06-16-2007, 06:45 PM
To have a multi-line select box, just set the size attribute. You don't have to set it to multiple if you want it to be single-select. There are a lot of double combo scripts out there on the Web. Google (http://www.google.com/search?hl=en&q=double+combo+javascript) it.

<select size="5"><option>Option1</option><option>Option2</option></select>

06-17-2007, 04:03 AM
I see what you're saying about the size attribute, I really don't need the "multiple" thing in there. That makes it work perfectly, thank you.

One of the results from the Google search you linked to was this one: http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_63.html
As you can see in that example, all of the select and option data is stored in the HEAD of the document, but is there a way to have it in a file instead?

06-17-2007, 05:06 AM
You can put the script in an external .js file and link it in the script src.

<script type="text/javascript" src="theScript.js"></script>
If the option items are dynamic and retrieved from the database or some other sources in the server, you can still link the file in the script src. You just need to set the content type to "text/javascript" in the server-side code and then output javascript. In the case of ASP, you do it like this:

<script type="text/javascript" src="theScript.asp"></script>

Response.ContentType = "text/javascript"
Response.Write "alert('test');"