auto fill 'http://' in input - Javascript jQuery

Javascript examples for jQuery:Form Input

Description

auto fill 'http://' in input

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
  <script>
   $(document).ready(function() {
    $('#urlForm').submit(function() {
     var url = $('#address');
     if(url.val().match(/^http:\/\//) == null) {
      url.val("http://" + url.val());
     }// w w w.j a va 2s . c o m
    });
   });
  
      </script> 
 </head> 
 <body> 
  <form id="urlForm"> 
   <input id="address" type="text"> 
   <button type="submit">Submit</button> 
  </form>  
 </body>
</html>

Related Tutorials