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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box quesion

Status
Not open for further replies.

ttea

IS-IT--Management
Feb 24, 2003
11
HK
There is a table in a form contain different combo boxes.

How can i return the combo boxs'values only when it is changed by the user and put the value in the string array??
 
be more specific. Using onchange would probably help you but it sounds like you just want someone to write a script for you.

Start the work and we'll help you learn. Gary Haran
 
I don't mean that asking others to write the script for me,I have also tried many times as i am a beginner of javascript only.I hope you can understand.

I am trying to use onchange, but i don't know how to put the option value in the array.

 
ok so you mean the option value inside an array?

The selected option is found using :

document.formName.elementName.options[document.formName.elementName.selectedIndex]

You can then add that to the end of an array either by using the index of the array :

var myArray = new Array();
myArray[0] = document.formName.elementName.options[document.formName.elementName.selectedIndex]

Or you could use push to add it directly to the end of the array :

var myArray = new Array();
myArray.push(document.formName.elementName.options[document.formName.elementName.selectedIndex])

If what you actually wanted was to add all the values of the combo inside an array you could use a for loop and add the option's value inside the array using push

var formElm = document.formName.elementName.options;
var len = formElm.length;
var myArray = new Array();

for (var i = 0; i < len; i++)
{
myArray.push(formElm)
}

I hope this helps you out.
Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top