user1981294
user1981294

Reputation: 3

How to add a hidden variable to input field

I had a working script, but I need to allow users to change a hidden variable if they choose to.

         <strong>Select</strong><br>
          <select class="inputClass" size="1" id="f1a" name="Board">
            <option value="Selected">Use</option>
            <option value="Selected">--------------------------</option>
            <option value="6">Floor Joist</option>
            <option value="4">Wall</option>
            <option value="8">Header</option>
            <option value="4">Rafter</option>
          </select>

So I added an input field.

<br>

           <strong>Board Use</strong> <br>

          <input class="inputClass" type="text"  id="f1" value="" size="12" name="Board Use">

I have spent the last two weeks trying different codes to get f1a.value into f1 input field. Then the user can choose to leave my value or put his own value in.

Any suggestions.

Upvotes: 0

Views: 86

Answers (1)

jholloman
jholloman

Reputation: 1979

You just need a simple onchange event on the select:

var f1a = document.getElementById("f1a");
var f1 = document.getElementById("f1");
f1a.onchange = function() {
  f1.value = f1a.value;
};

This will call the onchange function anytime the user chooses a new value in the select. The input can be overwritten at anytime.

http://jsfiddle.net/G3PGY/

https://developer.mozilla.org/en-US/docs/DOM/element.onchange

Upvotes: 2

Related Questions