0

I wish to output the value in option in the input value field. So if i select red i wish to output red in the input value

$(document).ready(function(){
    $("select").click(function(){
        $("input:text").val($this);
    });
});
<select>
  <option value="red">red</option>
  <option value="black">black</option>
  <option value="blue">blue</option>
</select>
<input type="text" id="input" value="">
<div id="output"></div>

1
  • 2
    $("input:text").val($(this).val()); - there is no $this in the change event handler, you can get the select input's value using $(this).val() Commented Apr 14, 2016 at 13:55

1 Answer 1

0

you should use .change() not click()

$(document).ready(function(){
    $("select").change(function(){
        $("input[type=text]").val($(this).val());
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value="red">red</option>
  <option value="black">black</option>
  <option value="blue">blue</option>
</select>
<input type="text" id="input" value="">
<div id="output"></div>

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.