Jump to content

Recommended Posts

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 ?  :P

 

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/
Share on other sites

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.  :shrug:

 

try

if(reg_n != null && reg_p != null && reg_email != null && reg_p_m != null && reg_n != "" && reg_p != "" && reg_email != "" && reg_p_m != "")

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293568
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293768
Share on other sites

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;
  }
}

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293771
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293874
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293910
Share on other sites

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;
}
}


Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293923
Share on other sites

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;
  }
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/252314-function-problem/#findComment-1293962
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.