/    Sign up×
Community /Pin to ProfileBookmark

string matching problem

hello i am trying to make a registration page for my school project .
I wrote a simple script that would check if my password and comfirmpassword fields match . Something is wrong , it always says unmatching password fields.

below are my codes

[CODE] <form name=”registration” action=”register.php” method=”post” onsubmit=”return checkData()”>

<table width=”417″ border=”0″>
<tr>
<td><font class=”duzyazi”><strong>Username:</strong></font></td>
<td><input name=”username” type=”text” class=”textarea” size=”30″ /></td>
</tr>
<tr>
<td><font class=”duzyazi”><strong>E-Mail Address:</strong></font></td>
<td><input name=”email” type=”text” class=”textarea” size=”30″ /></td>
</tr>
<tr>
<td><font class=”duzyazi”><strong>Confirm E-mail Address:</strong></font></td>
<td><font class=”duzyazi”><strong> </strong></font>
<input name=”confirmemail” type=”text” size=”30″ class=”textarea”/></td>
</tr>
<tr>
<td><font class=”duzyazi”><strong>Password: </strong></font></td>
<td><input name=”password” type=”text” class=”textarea” size=”30″ /></td>
</tr>
<tr>
<td><font class=”duzyazi”><strong>Confirm Password:</strong></font></td>
<td><input name=”confirmpass” type=”text” class=”textarea” size=”30″ /></td>
</tr>
<tr>
<td><input type=”submit” value=”RESIM” name=”register” /></td>
<td>&nbsp;</td>
</tr>
</table>
<br />
<br /><br />
</form>[/CODE]

and

[CODE]function checkData()
{

if(document.registration.username.value==””)
{
window.alert(“You can`t leave the username field blank!.. Please enter a valid Username”);
return false;
}
else if(document.registration.email.value.indexOf(“@”)==-1)
{
window.alert(“Please enter a valid Email Address”);
return false
}

else if(document.registration.password.value=””)
{
window.alert(“Password field can not be blank!”);
return false;
}

else if(document.registration.email.value!=document.registration.confirmemail.value)
{
window.alert(“Unmatching Email fields”);
return false;
}

else if(document.registration.password.value!=document.registration.confirmpass.value)
{
window.alert(“Unmatching password fields”);
return false;
}

else{
return true;
}
}
[/CODE]

other parts works fine , i just have problem with the password fields , i probably am missing something very wasy.

thanks

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMar 04.2008 — Change:
<i>
</i> else if(document.registration.password.value="")

to:

<i>
</i> else if(document.registration.password.value=="")
Copy linkTweet thisAlerts:
@barantamerauthorMar 04.2008 — i see that was an error too ?

But my problem is , i want to give an error when my password and comfirmpass fields do not match . Do u have any idea about that?
Copy linkTweet thisAlerts:
@skywalker2208Mar 04.2008 — It works when you change the form input from password to pass like this
[code=php]input name="pass" type="text" class="textarea" size="30" />[/code]

and then change everything in your javascript code to work with this.

I don't know if you know this but there is an input type of password that will hide the password value.

Example of input type password
Copy linkTweet thisAlerts:
@KorMar 04.2008 — But you have already done that here:
<i>
</i>else if(document.registration.password.value!=document.registration.confirmpass.value)
{
window.alert("Unmatching password fields");
return false;
}

Are there both elements input type=password?
Copy linkTweet thisAlerts:
@KorMar 04.2008 — It works when you change the form input from password to pass like this
[code=php]input name="pass" type="text" class="textarea" size="30" />[/code]

[/QUOTE]

Why? A password must be written in an input [B]type="password"[/B]; this is why this type exists.
Copy linkTweet thisAlerts:
@skywalker2208Mar 04.2008 — Why? A password must be written in an input [B]type="password"[/B]; this is why this type exists.[/QUOTE]
he isn't using input type of password. he is using text
Copy linkTweet thisAlerts:
@KorMar 04.2008 — ok, now, both input name="password" and input name="confirm" should be (for protection against trojans) type="password"
Copy linkTweet thisAlerts:
@barantamerauthorMar 04.2008 — thanks to everyone who replied.

I changed "password" to "pass" and it worked. I dont actually know why ?

I guess there is a conflict between the type and name
×

Success!

Help @barantamer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...