Reputation: 5
I'm trying to put the option value of my select in a input text i have this:
<select name="typers" id="contact-location" class="form-control">
<option value="Facebook">Facebook</option>
<option value="Twitter">Twitter</option>
<option value="Google +">Google +</option>
<option value="Autres">Autre</option>
</select>
And when i submit, i want that my input text to get the value of the option selected :
<input type="text" name="typers" value="MySelectedOption"/>
I have tried but without success... Somebody know how to do ?
Upvotes: 0
Views: 151
Reputation: 20636
$('input[type="Submit"]').click(function(){
$('input[type="text"').val($('#contact-location').val()); //input selector
});
Use this Fiddle Demo.
Upvotes: 0
Reputation: 194
You can use it: I assume your submit button id is submit
$('#submit').click(function(){
var text = $('#contact-location').val();
$('input [name=typers]').val(text);
})
Also i want to tell you your html is wrong input does not have a closing tag.It should be like this:<input type="text" name="typers" value="MySelectedOption"/>
Upvotes: 1
Reputation: 82241
You can use:
$('input[name=typers]').val($('#contact-location').val());
Upvotes: 3