How do I copy one drop down selection to another ...

J

Jeff

Hi, I am trying to set the value of one drop down select box to the
value of another drop down select box. I have the following in a
function.

document.formname.boxto.options[document.formname.boxto.selectedindex].v
alue =
document.formname.boxfrom.options[document.formname.boxfrom.selectedinde
x].value;

but I need to change the above line to allow the 4 references to "boxto"
and "boxfrom" to be dynamic so their values can be passed to the
function each time. Any ideas?
 
M

Martin Honnen

Jeff said:
Hi, I am trying to set the value of one drop down select box to the
value of another drop down select box. I have the following in a
function.

document.formname.boxto.options[document.formname.boxto.selectedindex].v
alue =
document.formname.boxfrom.options[document.formname.boxfrom.selectedinde
x].value;

but I need to change the above line to allow the 4 references to "boxto"
and "boxfrom" to be dynamic so their values can be passed to the
function each time. Any ideas?


function setSelect (name1, name2) {
var select1 = document.forms.formname.elements[name1];
var select2 = document.forms.formname.elements[name2];
select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;
}
 
J

Jeff

Martin Honnen said:
Hi, I am trying to set the value of one drop down select box to the
value of another drop down select box. I have the following in a
function.

document.formname.boxto.options[document.formname.boxto.selectedindex].v
alue =
document.formname.boxfrom.options[document.formname.boxfrom.selectedinde
x].value;

but I need to change the above line to allow the 4 references to "boxto"
and "boxfrom" to be dynamic so their values can be passed to the
function each time. Any ideas?


function setSelect (name1, name2) {
var select1 = document.forms.formname.elements[name1];
var select2 = document.forms.formname.elements[name2];
select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;
}

I get the following error message in IE 6:

'options' is null or not an object
 
M

Martin Honnen

Jeff said:
Martin Honnen said:
function setSelect (name1, name2) {
var select1 = document.forms.formname.elements[name1];
var select2 = document.forms.formname.elements[name2];
select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;
}

I get the following error message in IE 6:

'options' is null or not an object

Post the HTML of your form or a URL to it and your function call, then
tell us for which line the error is reported. I suspect you do not pass
the right parameters to the function.
 
J

Jeff

Martin Honnen said:
Martin Honnen said:
function setSelect (name1, name2) {
var select1 = document.forms.formname.elements[name1];
var select2 = document.forms.formname.elements[name2];
select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;
}

I get the following error message in IE 6:

'options' is null or not an object

Post the HTML of your form or a URL to it and your function call, then
tell us for which line the error is reported. I suspect you do not pass
the right parameters to the function.

http://207.235.5.120/test.php
 
J

Jeff

Jeff said:
Martin Honnen said:
function setSelect (name1, name2) {
var select1 = document.forms.formname.elements[name1];
var select2 = document.forms.formname.elements[name2];
select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;
}

I get the following error message in IE 6:

'options' is null or not an object

Post the HTML of your form or a URL to it and your function call, then
tell us for which line the error is reported. I suspect you do not pass
the right parameters to the function.

http://207.235.5.120/test.php

Problem solved, changed:

select1.options[select1.selectedIndex].value =
select2.options[select2.selectedIndex].value;

to:

select1.selectedIndex = select2.selectedIndex;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top