lofaifa Posted December 2, 2011 Share Posted December 2, 2011 this : function validateForm() { var r_n=document.forms["regist"]["regist_name"].value; var r_p1=document.forms["regist"]["regist_password1"].value; var r_p2=document.forms["regist"]["regist_password2"].value; var r_email=document.forms["regist"]["regist_email"].value; if (r_n==null || r_n=="" ) { var reg_n="username box left empty , please try again !<br/>"; } else if (r_p1==null || r_p1=="" || r_p2==null || r_p2=="") { var reg_p="one of the password boxes left empty , please try again !<br/>"; } else if (r_email==null || r_email=="") { var reg_email="e-mail box left empty , please try again!<br/>"; } else if (r_p1!==r_p2) { var reg_p_m="rewrite your passwords , they dont match!<br/>"; } if(reg_n!==null|| reg_p!==null || reg_email!==null || reg_p_m!==null || reg_n!=="" || reg_p!=="" || reg_email!=="" || reg_p_m!=="") { document.getElementById("reg_name").innerHTML=reg_n; document.getElementById("reg_password").innerHTML=reg_p; document.getElementById("reg_email").innerHTML="reg_email + reg_p_m"; return false; } } returns always TRUE . what to do ? Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/ Share on other sites More sharing options...
Spring Posted December 2, 2011 Share Posted December 2, 2011 Sorry, I don't use much pure javascript, but this doesn't look right. if(reg_n!==null|| reg_p!==null || reg_email!==null || reg_p_m!==null || reg_n!=="" || reg_p!=="" || reg_email!=="" || reg_p_m!=="") Should you be using Logical AND and also being using '!=' not '!==' Hopefully, I helped. try if(reg_n != null && reg_p != null && reg_email != null && reg_p_m != null && reg_n != "" && reg_p != "" && reg_email != "" && reg_p_m != "") Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293568 Share on other sites More sharing options...
haku Posted December 3, 2011 Share Posted December 3, 2011 also being using '!=' not '!==' != Checks that the values are equal. !== checks that the value AND type are equal. It's actually better to use !==, but this is more difficult as it requires paying more attention to what dataype your variables are holding. Many people have a difficult time doing this. Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293768 Share on other sites More sharing options...
haku Posted December 3, 2011 Share Posted December 3, 2011 function validateForm() { var r_n, r_p1, r_p2, r_email, reg_n, reg_p, reg_email, reg_pm; r_n=document.forms["regist"]["regist_name"].value; r_p1=document.forms["regist"]["regist_password1"].value; r_p2=document.forms["regist"]["regist_password2"].value; r_email=document.forms["regist"]["regist_email"].value; if (!r_n || r_n == "" ) { reg_n="username box left empty , please try again !<br/>"; } if (!r_p1 || r_p1 == "" || !r_p2 || r_p2 == "") { reg_p="one of the password boxes left empty , please try again !<br/>"; } if (r_email==null || r_email=="") { reg_email="e-mail box left empty , please try again!<br/>"; } else if (r_p1 !== r_p2) { reg_p_m="rewrite your passwords , they dont match!<br/>"; } if(reg_n !== "" || reg_p !== "" || reg_email !== "" || reg_p_m !== "") { document.getElementById("reg_name").innerHTML=reg_n; document.getElementById("reg_password").innerHTML=reg_p; document.getElementById("reg_email").innerHTML="reg_email + reg_p_m"; return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293771 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 still doesnt work .. this is the form <form name="regist" action="proc/regist_proc.php" onsubmit="return validateForm()" method="post"> <p>Your Username: <input type="text" name="regist_name" /></p> <p>Your Password: <input type="password" name="regist_password1" /></p> <p>Repeat Password: <input type="password" name="regist_password2" /></p> <p>Your E-mail: <input type="text" name="regist_email"/></p> <input type="submit" value="Register"> Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293874 Share on other sites More sharing options...
Spring Posted December 3, 2011 Share Posted December 3, 2011 document.getElementById("reg_name").innerHTML=reg_n; document.getElementById("reg_password").innerHTML=reg_p; document.getElementById("reg_email").innerHTML="reg_email + reg_p_m"; What are you doing here..? There is no element with the id = to "reg_name" I'm getting a null error. I think you should re-write this function. Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293910 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 i just didnt give u the full html code , its actually like this : <html> <head> <script type="text/javascript" src="javascript/reg_validation.js"></script> <title>Registration</title> </head> <body> <p>please fill up your informations :</p> <p id="reg_username" style="color:red"> <p id="reg_password" style="color:red"> <p id="reg_email" style="color:red"> <p id="error" style="color:red;"></p><br/> <form name="regist" action="proc/regist_proc.php" onsubmit="return validateForm()" method="post"> <p>Your Username: <input type="text" name="regist_name" /></p> <p>Your Password: <input type="password" name="regist_password1" /></p> <p>Repeat Password: <input type="password" name="regist_password2" /></p> <p>Your E-mail: <input type="text" name="regist_email"/></p> <input type="submit" value="Register"> <a href="index.php">Or go Back</a> </form> </body> </html> And the JavaScript function is : function validateForm() { var r_n, r_p1, r_p2, r_email, reg_n, reg_p, reg_email, reg_pm; var r_n=document.forms["regist"]["regist_name"].value; var r_p1=document.forms["regist"]["regist_password1"].value; var r_p2=document.forms["regist"]["regist_password2"].value; var r_email=document.forms["regist"]["regist_email"].value; if (!r_n || r_n == "" ) { reg_n="username box left empty , please try again !<br/>"; } if (!r_p1 || r_p1 == "" || !r_p2 || r_p2 == "") { reg_p="one of the password boxes left empty , please try again !<br/>"; } if (r_email==null || r_email=="") { reg_email="e-mail box left empty , please try again!<br/>"; } else if (r_p1 !== r_p2) { reg_p_m="rewrite your passwords , they dont match!<br/>"; } if(reg_n !== "" || reg_p !== "" || reg_email !== "" || reg_p_m !== "") { document.getElementById("reg_name").innerHTML=reg_n; document.getElementById("reg_password").innerHTML=reg_p; document.getElementById("reg_email").innerHTML="reg_email + reg_p_m"; return false; } } OR : function validateForm() { var reg_n=""; var reg_p=""; var reg_p_m=""; var reg_email=""; var r_n=document.forms["regist"]["regist_name"].value; var r_p1=document.forms["regist"]["regist_password1"].value; var r_p2=document.forms["regist"]["regist_password2"].value; var r_email=document.forms["regist"]["regist_email"].value; if (r_n==null || r_n=="" ) {reg_n="username box left empty , please try again !<br/>"; } if (r_p1==null || r_p1=="" || r_p2==null || r_p2=="") {reg_p="one of the password boxes left empty , please try again !<br/>"; } if (r_email==null || r_email=="") {reg_email="e-mail box left empty , please try again!<br/>"; } if (r_p1!==r_p2) {reg_p_m="rewrite your passwords , they dont match!<br/>"; } if(reg_n!=="" || reg_p!=="" || reg_p_m!=="" || reg_email!=="") { document.getElementById("reg_username").innerHTML=reg_n; document.getElementById("reg_password").innerHTML=reg_p + reg_p_m ; document.getElementById("reg_email").innerHTML=reg_email; return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293923 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 is ajax a more obv option to do this ?? cuz im really angry about this .. it worked for me for like 2 hours back then and then when i loaded the page for the last time it didnt work again and i didnt even touch the syntax of it ! Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293929 Share on other sites More sharing options...
haku Posted December 3, 2011 Share Posted December 3, 2011 reg_name != reg_username Fix the above problem, and your problem should be fixed. Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293938 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 showed the error then moved to another page .. Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293948 Share on other sites More sharing options...
haku Posted December 3, 2011 Share Posted December 3, 2011 You're welcome for the assistance by the way. I thought I should say so since you were so gracious with your appreciation. function validateForm() { var r_n, r_p1, r_p2, r_email, reg_n, reg_p, reg_email, reg_pm; r_n=document.forms["regist"]["regist_name"].value; r_p1=document.forms["regist"]["regist_password1"].value; r_p2=document.forms["regist"]["regist_password2"].value; r_email=document.forms["regist"]["regist_email"].value; if (!r_n.length) { reg_n="username box left empty , please try again !"; } if (!r_p1.length || !r_p2.length) { reg_p="one of the password boxes left empty , please try again !"; } if (!r_email.length) { reg_email="e-mail box left empty , please try again!"; } else if (r_p1 !== r_p2) { reg_p_m="rewrite your passwords , they dont match!"; } if(reg_n.length || reg_p.length || reg_email.length || reg_p_m.length) { document.getElementById("reg_username").innerHTML = reg_n; document.getElementById("reg_password").innerHTML = reg_p; document.getElementById("reg_email").innerHTML= "reg_email + reg_p_m"; return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293962 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 i prefer giving back the favor rather than saying thanks i apologize if u thought im rude because of that and u should know i appreciate every things uv done .. u and spring . Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293968 Share on other sites More sharing options...
lofaifa Posted December 3, 2011 Author Share Posted December 3, 2011 and there is something wrong : the erorrs display like this username box left empty , please try again ! one of the password boxes left empty , please try again ! reg_email + reg_p_m Quote Link to comment https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.