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:

http://jsfiddle.net/dgurj/

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();     }); }); 

fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -