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

Update Textbox based on Value of Select Box 1

Status
Not open for further replies.

PsychoticBadgers

IS-IT--Management
Jan 25, 2005
10
GB
I can update a text box with the contents of another text box...

Code:
function SendInfo()
 {
 window.document.Formname.[COLOR=green]Textname2[/color].value=window.document.Formname.Textname1.value
 }

Here's the tricky bit:
[COLOR=red yellow]I want it to choose which text box to update based on a selection box.[/color]

I have the following code, but i don't think it likes having two "options" bits...

Code:
function SendInfo()
 {
 window.document.Formname.[COLOR=green]options[window.document.Formname.SelectBoxname.options[window.document.Formname.SelectBoxname.selectedIndex].value][/color].value=window.document.Formname.Textname1.value
 }

How else can I do this?
 
I have a select list, one Textarea, and multiple hidden text boxes.

The user will choose an option from the select list, which will determine which hidden text box will update with any text then input into the Textarea.

Clear as mud?
 
there's no such thing as Form.options. It should be Form.elements.

Try this (and why not break your code into more than one line so it's readable?):

Code:
function SendInfo() {
    var f = document.forms['Formname'];
    var e = f.elements;
    var sel = e['SelectBoxname'];

    var fieldName = sel.options[sel.selectedIndex].value;
    
    e[fieldName].value = e['Textname1'].value;
 }

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
My apologies for the lengthy lines of code,
and my thanks for your fast & effective response!
 
If anyones interested:

If you merge the above code together and remove the variables,
then you'll see that the answer to this was even simpler than I thought...

The code I had was:
Code:
function SendInfo()
 {
 window.document.Formname.
    [COLOR=red]options[/color][window.document.Formname.SelectBoxname.
    options[window.document.Formname.SelectBoxname.selectedIndex]
    .value]
    .value = window.document.Formname.Textname1.value
 }

The code I needed was:
Code:
function SendInfo()
 {
 window.document.Formname.
    [COLOR=red]elements[/color][window.document.Formname.SelectBoxname.
    options[window.document.Formname.SelectBoxname.selectedIndex]
    .value]
    .value = window.document.Formname.Textname1.value
 }

Still thanks though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top