By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a


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

P: n/a

"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

P: n/a


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

P: n/a
"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

P: n/a
"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.