jQuery Input value select


/ Published in: JavaScript
Save to your folder(s)

Click on an input field with a prefilled value, if that value equals the default then select it, if not leave it as it was. Relies on jQuery.


Copy this code and paste it in your HTML
  1. $("input[name=forname], input[name=surname]").focus(function(){
  2. var defaultText = $(this).val();
  3. if(defaultText === "Forename" || defaultText === "Surname"){
  4. $(this).select();
  5. }
  6. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.