[Javascript] How can I add an element to a select box

Omar Saleh osaleh at sapient.com
Wed Aug 8 18:09:28 CDT 2001


How can I add or delete an element from a Select Box using JavaScript ? i
basically have two Select boxes (set to multiple), when I double click on
select box 1, i need to add the element I double clicked on to box 2. If i
double click on an element in box 2, then I need that element to be deleted.
Here is the page that I have now that does not work.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="javaScript">
function process_group(thisform,sAction)
 {
  if (sAction == '1'){
    DataForm.D1.add (DataForm.D2.options[DataForm.D2.selectedIndex].value);
  else
    DataForm.D1.remove(DataForm.D1.selectedIndex);
}
</script>
</head>

<body>

<form method="post" name="DataForm" action="--WEBBOT-SELF--"><!--webbot
bot="SaveResults" U-File="fpweb:///_private/form_results.txt"
  S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
  <p><select size="1" name="D1"  multiple
ondblclick="process_group(this.document,'0')" style="HEIGHT: 189px; WIDTH:
73px">
  </select><select size="1" name="D2"
ondblclick="process_group(this.document,'1')" multiple style="HEIGHT: 144px;
WIDTH: 90px">
  <option value="a">a</option>
  <option value="b">b</option>
  <option value="c">c</option>
  &nbsp;
  </select><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>

</body>

</html>

Thx.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20010808/64a45d6d/attachment.htm>


More information about the Javascript mailing list