javascript - Focus a textfield after its value with jquery -
i made form in select option dropdown menu. when option selected value set textfield. want happen focuses on textfield after value. example: select facebook drop down , "http://www.facebook.com/" appears value of textfield. when facebook selected focus goes textfield after last character of value added.
i made jsfiddle have thusfar:
js:
$(document).ready(function() { //add right url prefix social media $('select').change(function() { console.log(this.value); if(this.value == "facebook"){ $('#social-url').val("http://www.facebook.com/"); } if(this.value == "twitter"){ $('#social-url').val("http://www.twitter.com/"); } if(this.value == "linkedin"){ $('#social-url').val("http://www.linkedin.com/"); } }); });
just add focus()
trigger after value set, so:
$('#social-url').val("http://www.twitter.com/").focus();
here's how i'd it:
$(document).ready(function() { $('select').on('change', function() { $('#social-url').val("http://www." + this.value.tolowercase() + ".com/") .focus(); }); });
Comments
Post a Comment