Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box

Status
Not open for further replies.

enak

Programmer
Jul 2, 2002
412
US
I need to be able to move (or copy) data from one list box to another when
a button is clicked.

I am having a problem with the recognition of the Options object. Here is
the code below:

<script>

function fromPartiesToPlaintiff()
{

var index = document.frmRelatedParties.selParties.selectedIndex;
var text = document.frmRelatedParties.selParties.options[index].text;
var value = document.frmRelatedParties.selParties.options[index].value;
var len = document.frmRelatedParties.selPlaintiff.length;

var new_element= document.createElement(&quot;option&quot;);
new_element.text = text;
new_element.value = value;
new_element.selected=true;
document.frmRelatedParties.selPlaintiff.options[len]=new_element;

}

</script>

<form name=frmPlaintiff>
<input type=button name=addPlaintiff value=&quot;Add Plaintiff --->>>&quot; onClick=&quot;fromPartiesToPlaintiff()&quot;>
</form>

I get an error in the function when this line is reached:
document.frmRelatedParties.selPlaintiff.options[len]=new_element;

Any ideas????

TIA
Nate

 
As written, the problem line is trying to add an item to an array. In context, however, it should be trying to append an
Code:
option
element to an existing
Code:
select
element. Try --

Code:
document.frmRelatedParties.selPlaintiff.appendChild(new_element)
 
That does not work. I get an error message of &quot;Object doesn't support this property or method&quot;

I have tried add(new_element) with the same results.

Thanks
Nate
 
Use this:
var new_element = new Option();

instead of this:
var new_element= document.createElement(&quot;option&quot;);
 
What is
Code:
document.frmRelatedParties.selPlaintiff
? Context implies something like --
Code:
<select id=&quot;selPlaintiff&quot;>
  <option value=&quot;mad&quot;>Charles Manson</option>
  <option value=&quot;eccentric&quot;>Winona Ryder</option>
</select>
inside of
Code:
<form id=&quot;frmRelatedParties&quot;>

The form can also be
Code:
name
'd &quot;frmRelatedParties&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top