470,594 Members | 1,415 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

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

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?
Jul 23 '05 #1
5 8932


Jeff wrote:
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;
}

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40******@olaf.komtel.net...


Jeff wrote:
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;
}

--

Martin Honnen
http://JavaScript.FAQTs.com/


I get the following error message in IE 6:

'options' is null or not an object


Jul 23 '05 #3


Jeff wrote:
"Martin Honnen" <ma*******@yahoo.de> wrote
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40********@olaf.komtel.net...


Jeff wrote:
"Martin Honnen" <ma*******@yahoo.de> wrote
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/


http://207.235.5.120/test.php
Jul 23 '05 #5
"Jeff" <jm**@mail.com> wrote in message
news:k6Unc.23107$iF6.2286339@attbi_s02...
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40********@olaf.komtel.net...


Jeff wrote:
"Martin Honnen" <ma*******@yahoo.de> wrote
> 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.
--

Martin Honnen
http://JavaScript.FAQTs.com/


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;
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dan | last post: by
3 posts views Thread by John Walker | last post: by
5 posts views Thread by E.T. Grey | last post: by
reply views Thread by TD | last post: by
3 posts views Thread by CSharpguy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.