Match string start for 'http://' in input - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Match string start for 'http://' in input

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function checkUR(abc){//from   ww  w.jav  a 2 s .  com
    string = abc.value
    if(!(/^http:\/\//.test(string))){
        string = "http://" + string;
    }
    abc.value=string
}

      </script> 
   </head> 
   <body> 
      <form> 
         <input type="url" name="someUrl" onkeyup="checkUR(this)"> 
      </form>  
   </body>
</html>

Related Tutorials