...

View Full Version : textbox ith checkbox validation on submit



shajiuddin
09-18-2011, 12:30 PM
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

xelawho
09-18-2011, 02:51 PM
one way:



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")
}
}
}

shajiuddin
09-18-2011, 03:12 PM
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

shajiuddin
09-18-2011, 03:19 PM
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

xelawho
09-18-2011, 04:55 PM
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)

shajiuddin
09-18-2011, 08:47 PM
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

xelawho
09-18-2011, 08:58 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum