473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9058


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
5
by: SirPoonga | last post by:
I think I'd have to do a combination of ASP and javascript to do this. What I want to do fill the first drop down box with values from a database query. Then based off that selection fill in the...
2
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
5
by: E.T. Grey | last post by:
I have a form that is populated with a drop down list and a list box. I want to be able to automatically populate the list box, whenever a user selects a new item from the drop down list. Is...
0
by: TD | last post by:
I have a combobox that is sometimes slow to drop down when clicked on. If you select an item in the list that is near the top of the list then the next time you click on the combobox it drops down...
3
by: CSharpguy | last post by:
I have 3 drop downs that are populated from the databasem 4 of my web pages need to have this drop down, how can I trap the selection made in the drop down and popuate my grid on my form?
2
by: ponyeyes | last post by:
Hi There, I am a bit of a newbie to PHP programming and I would like to know how I can place a selected drop down option into a PHP variable and then produce an sql query which incorporates this...
1
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.