FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Javascript Woes, its ignoring my ifs!

   
Author Topic: Javascript Woes, its ignoring my ifs!
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
code:
function checkForm()
{
var flgError = 0;
var errorMsg = "";
try {
if( document.edit.username.value == "" )
{
alert("Hello");
errorMsg+= "username cannot be left blank.\n";
document.edit.username.focus();
}
if( document.edit.public_name.value == "" )
{
alert("Hmm");
errorMsg+= "public_name cannot be left blank.\n";
document.edit.public_name.focus();
}
if( document.edit.firstname.value == "" )
{

errorMsg+= "firstame cannot be left blank.\n";
document.edit.firstname.focus();
}
if( document.edit.lastname.value == "" )
{
errorMsg+= "lastname cannot be left blank.\n";
document.edit.lastname.focus();
}
if( document.edit.email.value == "" )
{
errorMsg+= "email cannot be left blank.\n";
document.edit.email.focus();
}
if( document.edit.password.value == "" )
{
alert("Hrrm");
errorMsg+= "password cannot be left blank.\n";
document.edit.password.focus();
}
if( errorMsg != "" )
{
alert(errorMsg);
return false;
}

return true;
}

It goes in here just fine, but it doesn't work. Putting an Alert before the last if is ignored it seems to only bother checking the first 2 ifs and then jumps over to return true its not making any sense.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Your braces are mismatched.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Ignore the Try {
IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
code:
<html>
<head><title>Edit A Account for Admins</title>
<script language ="javascript" src="../cgi-bin/java.js"></script>
</head>
<body>
<form name="edit" action="../cgi-bin/adminEdit.pl" method="post" onSubmit="return checkForm()">


<table>

<tr>
<td>Username:</td><td><input type="text" name="username" value="Raenir" /></td><br>
</tr>
<tr>
<td>Username:</td><td><input type="text" readonly="yes" name="username2" value="Raenir" /></td><br></tr>
<tr>
<td>Public Name:</td><td><input type="text" name="public_name" value="Archmagi"/></td><br>
</tr>
<tr>
<td>First Name:</td><td><input type="text" name="firstName" value="Rae"/></td><br>
</tr>
<tr>
<td>Last Name:</td><td><input type="text" name="lastName" value="Nir"/></td><br>
</tr>
<tr>
<td>Email:</td><td><input type="text" name="email" value="raenir@gmail.com"/></td><br>
</tr>
<tr>
<td>Password:</td><td><input type="text" name="password" value="dr5g0n"/></td><br>
</tr>
<tr>
<td>Location:</td><td><input type="text" name="location" value=""/></td><br>
</tr>
<tr>
<td>Homepage:</td><td><input type="text" name="homepage" value=""/></td><br>
</tr>
<tr>
<td>Occupation:</td><td><input type="text" name="occupation" value=""/></td><br>
</tr>
<tr>
<td>Interests:</td><td><input type="text" name="interests" value=""/></td><br>
</tr>
<tr>
<td>ICQ:</td><td><input type="text" name="icq_number" value=""/></td><br>
</tr>
<tr>
<td>MSN:</td><td><input type="text" name="msn" value=""/></td><br>
</tr>
</table>

<input type="submit"><br>


</form>
</html


IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
HUZZAH! I Solved it!
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
quote:
Originally posted by Blayne Bradley:
Ignore the Try {

I can do so, but surely even you cannot possibly believe that the Javascript engine will? [Roll Eyes]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
No, you do not understand, that is an error in COPYING to Hatrack, in reality the script I am playing with does not have the try/catch code at all. Hench it is not the problem.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
So not only do you bring Hatrack trivial problems which you proceed to solve in five minutes, you can't even copy your code correctly and make it possible for us to diagnose it? Dude, this is kindergarten stuff. Sharpen up.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
I assure you a spent a good hour on it before posting.
IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
Really? What was the problem?
Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
Looking at the code, and trying to guess what you're trying to accomplish, I'm assuming you just discovered the benefit of using "else"...
Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
Lyrhawn
Member
Member # 7039

 - posted      Profile for Lyrhawn   Email Lyrhawn         Edit/Delete Post 
quote:
posted by Blayne:
Javascript Woes, its ignoring my ifs!

Well so long as your "ands" and "buts" are still functional, you aren't out of options yet.
Posts: 21898 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
no the point is is that if there are MANY blank fields then the popup alert will display all of the blank fields to inform the user, having else's would only show one. The problem I figured out was that there was a syntax error in the javascript which it turns out I didnt notice until I posted, the variable names for firstName and lastName were wrong in my JS and didnt match the names of the html fields.
IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2