Welcome to WebmasterWorld Guest from 54.225.31.78

Forum Moderators: open

Message Too Old, No Replies

How to fill a <input type="hidden"> using Javascript

     
10:59 am on Oct 29, 2009 (gmt 0)

5+ Year Member



I want to complete my form with a bit of Javascript (which I know next to nothing about, to fill out a hidden input field).

The input field is:

<input type="hidden" name='field[537,0]' value='' />

the dropdown selection positions are:

<select name='field[539,0] >
<option value='Herr'>Herr</option>
<option value='Frau'>Frau</option>

the command I am looking for would be:

if "Herr" is selected, add "sehr geehrter" to
"field[537,0]" and if "Frau" is selected add "sehr geehrte".

How does that get done?

4:40 pm on Oct 29, 2009 (gmt 0)

5+ Year Member



Add something like this to your <select> tag:

<select name="field[539,0]" id="field[539,0]" onChange="updateHidden(this.value);">

Then you need a function to do the updating...something like:

function updateHidden (choice) {
hiddenField = document.getElementById('fieldid');
if(choice == "Herr") { hiddenField.value = "sehr geehrter"; }
if(choice == "Frau") { hiddenField.value = "sehr geehrte"; }
}

Not tested. But you get the idea, right?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month