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
<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