user3631510
user3631510

Reputation: 5

Put an option value in a input text

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

Answers (3)

Shaunak D
Shaunak D

Reputation: 20636

$('input[type="Submit"]').click(function(){
    $('input[type="text"').val($('#contact-location').val()); //input selector
});

Use this Fiddle Demo.

Upvotes: 0

Anurag Jain
Anurag Jain

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

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use:

$('input[name=typers]').val($('#contact-location').val());

Working Demo on select change

Upvotes: 3

Related Questions