I want to use java script to select all of the options in a multiple select box. I know how to do that part of it but I want each value submited to the next page. In order to do that I believe i need to name the select box with [] on the end of it. I can't get javascript to perform the function I wrote to select all of the options in the select box with [] appended to the name. Here is an example of what I got now:
function selectAll(){
for (var i = 0; i < document.forms[0].select.length; i++){
document.forms[0].select.selected = true;
}
}
<html>
<form>
<select name=select>
<option value=1>1</option>
<option value=2>2</option>
</select>
<input type=submit value=submit onsubmit='selectAll()'>
</form>
</html>
this does not work:
function selectAll(){
for (var i = 0; i < document.forms[0].select[].length; i++){
document.forms[0].select.selected = true;
}
}
<html>
<form>
<select name=select[]>
<option value=1>1</option>
<option value=2>2</option>
</select>
<input type=submit value=submit onsubmit='selectAll()'>
</form>
</html>
Does anyone know how to get around this?