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();
Comments
Post a Comment