3

I was wondering of a quick way possibly using jQuery of changing an INPUT's value using SELECT.

Any help would be appreciated,

Thanks!

4 Answers 4

8

Bind an event handler to the <select> which will assign the selected value as the input's value:

$("#theSelect").change(function() {
    $("#someInput").val($(this).val());
});

Depending on your specific requirements, you may or may not need to trigger the handler once on page load (will need if the input is to be set to the initially selected option).

$("#theSelect").change(function() {
    $("#someInput").val($(this).val());
}).change(); // trigger once if needed

You can try it here.

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

Comments

2
$('select').change(function(){
    $('input').val($(this).val());
});

Comments

2

Do you mean set the value of a text box to the value of a drop down list when it is changed? Do that like this:

$("#mySelect").change(function(){
    $("#myInput").val($(this).val());
}

Comments

0
<input type="text" id="demoInput" /> 

<select id="demoSelect" />
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>


$('#demoSelect').change(function(){
    $('#demoInput').val($(this).val());
});

http://jsfiddle.net/praveen_prasad/7GUaq/

Comments

Your Answer

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