javascript - Make input value depend on `select option` selection -


basically if male selected, make input named pronoun have value of his. else, make input named pronoun have value of her.

<select name="sex">     <option value="male">male</option>     <option value="female">female</option> </select> <input type="text" name="pronoun" value="" placeholder="pronoun" /> 

try

$("select").change(function() {    if($(this).val() == 'male'){       $('input[name=pronoun]').val('his')    }    else{       $('input[name=pronoun]').val('her')     } }); 

or

$("select").change(function() {     $('input[name=pronoun]').val(($(this).val() == 'male') ? 'his' : 'her'); }).change(); 

fiddle


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -