Dynamic Dropdowns with Multiple Forms

Question:You have a great script for creating dynamic drop down boxes. But how would you adapt the script so it could be used for multiple forms in the same html document? i.e myform1, myform2 etc.
Richard Vaughan

Answer:To adapt the script for use in multiple forms on the same page amend the setOptions calls in the html to pass the form name as a second parameter eg:

setOptions(document.form1.optone.options[ document..form1.optone.selectedIndex].value,"form1");

You then amend the code at the top of the javascript to read as follows

function setOptions(chosen,theform) {
var selbox = document.theform.opttwo;

This then uses the one function to populate the dynamic lists for each of the dropdowns making it easy to share the content between the dropdowns if required.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow