Click to See Complete Forum and Search --> : multiple select drop dow-neat-a bit of further help


rjusa
11-16-2003, 11:18 PM
I have the following routine which allows me to select multiple choices in a drop down and then write the highlighted selections:

<body>
<form name="form1">
<select name="select1" size="4" multiple>
<option name="option1" value="Alabama">Alabama</option>
<option name="option2" value="Alaska">Alaska</option>
<option name="option3" value="Arizona">Arizona</option>
<option name="option4" value="Arkansas">Arkansas</option>
</form>
<script language="Javascript">
if (document.form1.select1.options[0].selected)
document.write("" + document.form1.select1.options[0].value + "<br/>");
if (document.form1.select1.options[1].selected)
document.write("" + document.form1.select1.options[1].value + "<br/>");
if (document.form1.select1.options[2].selected)
document.write("" + document.form1.select1.options[2].value + "<br/>");
if (document.form1.select1.options[3].selected)
document.write("" + document.form1.select1.options[3].value + "<br/>");
</script>
</body>

OK, so probably the easier Q first:

1) how would you incorporate a "loop" to go through all 50 states instead of coding for each?

2) is there a way to automatically have a text box inserted (appear) next to the state(s) if they are written?

Thanks,
Ron

gil davis
11-17-2003, 01:20 PM
To answer your first question:

for (var i=0; i<document.form1.select1.options.length; i++)
{if (document.form1.select1.options[i].selected)
{document.write(document.form1.select1.options[i].value + "<br/>");}
}

I don't know what you mean by "automatically have a text box inserted", so I'll pass on the second question.