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!

Movel all values of select box to text box 1

Status
Not open for further replies.

rob51383

Programmer
Jun 23, 2004
134
US
I have a select box that users add new options to dynamically. When they submit the form I need all of the select box values sent to a perl script. I need to move all the values of the select box to a hidden textbox and I will retreiv the values of the hidden textbox as the input. The different values need to be sepereated by a comma. Thanks
 
This code should do what you want:


Code:
function changeValue(src, targ) {
    var vals = '';
    for ( var i = 0; i < src.options.length; i++ ) {
        if ( vals.length > 0 ) vals += ',';
        vals += src.options[i].value;
    }
    targ.value = vals;
}

Here is how you would call it:

Code:
<form name="f" onsubmit="changeValue(this.selectboxname, this.hiddenfieldname)">
...
...
</form>

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top