Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    textbox ith checkbox validation on submit

    I have a simple html form with 2 text fields and submit button

    1 user name
    2 pwd/token

    and 1 checkbox 'First time user'


    if 'first time user' is selected then the 'Submit' button to be enabled only if the customer puts exactly 6 digits on pwd/token.

    if it's unchecked then the submit button to be enabled only if the customer enters 10 digits(pin_token code)

    please send me code will be very thankful for your help

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,984
    Thanks
    56
    Thanked 557 Times in 554 Posts
    one way:

    Code:
    html:
    <input type="button" value="Login" onclick="userCheck()">
    <input type="text" id="user"></input>
    <input type="text" id="pwd"></input>
    
    <input type="checkbox" id="check" /> Check if first time user.
    
    js:
    
    function userCheck () {
    var box=document.getElementById("check");
    var pwdlng=document.getElementById("pwd").value.length;
    var usr=document.getElementById("user").value;
     if (box.checked==true) {
     if(pwdlng==6)  {
    alert("welcome new user " +usr+"!")
    		} else{
    alert("New user? please enter exactly 6 digits in the password field")
    		}
    	}
     if (box.checked==false) {
     if (pwdlng==10) {
    alert("welcome back, " +usr+"!")
    		} else{
    alert("Already got an account, " +usr+"? Please enter your 10 digit access key")
    		}
    	} 
    }
    Last edited by xelawho; 09-18-2011 at 03:01 PM.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hi xelawho and everyone here,

    Thank you so much for your reply and this code is working some how. but please see my requirement again. there are 2 conditions for enabling 'Submit button'

    1. if 'first time user' is checked and if the customer puts exactly 6 digits on pwd/token then the 'Submit' button to be enabled only

    2. if 'first time user' unchecked and customer enters 10 digits on pwd/token then the 'Submit' button to be enabled only

    please send me code will be very thankful for your help

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hi xelawho,

    your logic is 100% correct but enabling and disabling of 'Submit' button is more important instead of showing alert boxes. please consider about it

    Regards

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,984
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Code:
    html:
    
    <input type="button" id="butt" value="Login" disabled="disabled" onclick="">
    <input type="text" id="user"></input>
    <input type="text" id="pwd" onkeyup="userCheck()"></input>
    
    <input type="checkbox" id="check" /> Check if first time user.
    
    js:
    
    <script type="text/javaScript">
    function userCheck () {
    document.getElementById("butt").disabled=true;
    var box=document.getElementById("check");
    var pwdlng=document.getElementById("pwd").value.length;
     if (box.checked==true&&pwdlng==6) {
    document.getElementById("butt").disabled=false;
    	}
     if (box.checked==false&&pwdlng==10) {
    document.getElementById("butt").disabled=false;
    	} 
    }
    </script>
    (and please don't send me private messages telling me that your post is urgent... it's Sunday morning where I am)
    Last edited by xelawho; 09-18-2011 at 06:19 PM.

  • Users who have thanked xelawho for this post:

    shajiuddin (09-18-2011)

  • #6
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts
    hi xelawho,

    it's working fine but when firstly we put 6 digits in pwd field and check the new user checkbox then login button becomes active but just after when we erase 6 digits then login button still remain ative......it's a small bug can u please check it again

    regards

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,984
    Thanks
    56
    Thanked 557 Times in 554 Posts
    I edited the code at 11:19 to deal with that (and also to disable the button if they keep entering digits after the target number had been reached).

    if you are using code that I posted before then, try what's in post #5 now. That solves that issue I think but get back to me if it doesn't.

    And stop sending me private messages. I can see when you have made a new post - you don't have to tell me about it.

  • Users who have thanked xelawho for this post:

    shajiuddin (09-19-2011)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •