Wednesday, October 9, 2013

useragent and input switch

<!DOCTYPE html>
<html>
<head>
<title>vivekmras.webhostingbuilders.com</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
 
</head>
<body>

<div  id="login">



    <label for="name">Login value:</label>
    <input type="text" name="name" id="name" value=""  />
   

           

    <label for="password">Password:</label>
    <input type="password" name="password" id="password" value="" />
   
   

   

           
 <button type="submit" data-theme="e" >Submit</button>

</div><!-- /content -->
        <script>
            function isNumberKey(evt, y){
                var next=y.tabIndex;
                console.log('next='+next);
                document.getElementById("passwrdnew").focus();
               
                var charCode = (evt.which) ? evt.which : event.keyCode;
    alert("charCode="+charCode);
    var userAgent = navigator.userAgent.toLowerCase();
    if ((userAgent.search("android") > -1) && (userAgent.search("mobile") > -1) && (userAgent.search("chrome") > -1)){
        alert("android mobile chrome");
    }
                       
                var mytextvalue = document.getElementById("passwrd").value;
               // alert("mytextvalue="+mytextvalue);
               //var str="myfile.doc";
               //alert(mytextvalue);
               if(mytextvalue.toString().indexOf('-') !== -1){
                   alert("value avialable");
               }
                var value =  evt.target.value;
               // alert("value="+value);
                if(mytextvalue==="1-"){
                    //alert("value="+mytextvalue);
                }
               
    var charCode = (evt.which) ? evt.which : event.keyCode;
    //alert("charCode="+charCode);
     if(charCode === 45 || charCode === 46 ){
       // alert("1");
       //var string = "Hello";
        var str = mytextvalue.substring(0, mytextvalue.length);
        //alert(str);
      document.getElementById("passwrd").value=str;
      //alert("value="+value);
        return false;
     }
    if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode === 45 || charCode === 46 )){
        //alert("charCode="+charCode);
        //evt.preventdefault();
        return false;
        //setTimeout(function(){},1);
    }else{
        return true;
       // evt.preventdefault();
    }

    }
   
   document.getElementById("passwrdnew").keydown(function(event){
        alert(event.keyCode);
    });
        </script>
       
       
        <div  id="login1">
    <label for="password">Password:</label>
    <input type="number" id="passwrd" tabindex="1" pattern="[0-9]*" onkeydown="return isNumberKey(event, this);"/>
   
    <label for="login">login:</label>
    <input type="text" id="passwrdnew"  onkeydown="return isNumberKey(event);"/>  
        </div>

</body>


</html>

No comments:

Post a Comment