faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 17 people (47%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I submit an entire multi-select list without the user needing to manually select them all.

Apr 28th, 2004 08:01
Steve Thorn, Sebastiaan Lubbers,


Why not add a checkbox to select all items in the list:

<form name="myform" method="get" action="myaction.php">
<select name="items" multiple>
  <option value=1>Item 1
  <option value=2>Item 2
  ...
</select>
<input type="submit" name="submit" value="Submit Form!">
<input type="checkbox" name="selall" onclick="select_all()">Select all
</form>

Then use this script to select all items in the SELECT list:

function select_all() {
  var tmp = document.myform.selall.checked ? true : false;
  for (var i=0; i<document.myform.items.length; i++)
    document.myform.items[i].selected = tmp;
}