razor
razor

Reputation: 111

How to get select box option value in a input text field

Here is my code:

<select name="art_type">
    <option value="ra">Research Article</option>
    <option value="rea">Review Article</option>
    <option value="re">Reviews</option>
    <option value="op">Opinions</option>
    <option value="le">Letters to the Editor</option>
</select>

<input style="border: none;" type="text" id="get_id_val" value="">

So whatever value user selects from the select box that value should be entered in the textbox. How to do that?

Upvotes: 2

Views: 4700

Answers (3)

Sergio
Sergio

Reputation: 28845

Try this:

$('select[name=art_type]').on('change', function () {
    var select = $(this).find('option:selected').val()
    $('#get_id_val').val(select)
});

Demo here

Upvotes: 1

gp.
gp.

Reputation: 8225

$("select").on("change", function(){
   $("#get_id_val").val( this.options[this.selectedIndex].value );
});

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388446

Try

jQuery(function($){
    var $idval = $('#get_id_val');
    $('select[name="art_type"]').change(function(){
        $idval.val($(this).val())
    }).triggerHandler('change')
})

Demo: Fiddle

Upvotes: 1

Related Questions