There are four scenarios in password validation.
1) If pass1 is empty alert should popup
2) If pass2 is empty alert should popup
3) If pass1 is not equal to pass2 or vice versa alert should popup or if any of field left empty.
4) And last is of submitssion of form.
I have stuck in point 3 where if by mistake user forget to enter confirm password.
Here is my code i am having issue with this. I need help
.js
function textbox()
{
var txt = document.form1.txtname;
if(txt.value == "" )
{
alert("please type somthing ");
txt.focus();
return false;
}
else
{
alert(" you type: " + txt.value + " value approved ");
}
return true;
}
function password()
{
var pass1=document.form1.txtpass1.value;
var pass2=document.form1.txtpass2.value;
if(pass1 == "")
{
if (pass2 == "")
{
alert("please type password");
}
return false;
}
if(pass1 != pass2)
{
alert("password does not match");
return false;
}
else if(pass2 == "")
{
alert("confirm password is required");
return false;
}
return true;
}
umair mohsinPosted Mar 9, 2015, 1:57 PM
you are logically correct.your previous answer is also correct but as you can seemy code i want to access all the form elements using document.form object like
docment.form1.rb;
rb is for radiobutton name property. i need to access form elements using above mentioned object. above code is for accessing password value or validate password if there are any errors in the form.can you help me in this regard
Rahul BansalPosted Mar 9, 2015, 10:33 AM
function password(){
if(documnet.getElementById('txtname').value=='')
{//alert() return false
}
if(documnet.getElementById('txtpass1').value=='')
{//alert()return false
}
if(documnet.getElementById('txtpass2').value=='')
{//alert() return false
}
if(documnet.getElementById('txtpass1').value!=documnet.getElementById('txtpass2').value
{//alert() return false
}else{
//return true
}