0

I have a HTML file with a simple drop down list.

Upon selecting one of the choices, I want the choice to be stored in a hidden input.

 <div id ="mainContent">
    <span style="font-size: 15px;"> Category : </span> <select id="selectid" name="filecategory">
                    <option value="A">A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                    <option value="E">E</option>
           </select>
          <br /><br />
 <input type="hidden"  name="filecategory" value="XXX" /> 
    </div>

I did some research online and came up with this handler code upon detecting a change event in the drop down list.

 $("#selectid").change(function(){
                   alert('change called');
                });

Can someone tell me how I can set the hidden input via this handler ?

1 Answer 1

3

Solved here:

$("#selectid").change(function(){
  $("input[name='filecategory']").val($(this).val())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select id="selectid" name="filecategory">
  <option value="A">A</option>
  <option value="B">B</option>
  <option value="C">C</option>
  <option value="D">D</option>
  <option value="E">E</option>
</select>
           
<input type="hidden"  name="filecategory" value="XXX" />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.