This is topic Javascript Woes, its ignoring my ifs! in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=054424

Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
Your braces are mismatched.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Ignore the Try {
 
Posted by Blayne Bradley (Member # 8565) on :
 
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


 
Posted by Blayne Bradley (Member # 8565) on :
 
HUZZAH! I Solved it!
 
Posted by King of Men (Member # 6684) on :
 
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]
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 
Posted by King of Men (Member # 6684) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I assure you a spent a good hour on it before posting.
 
Posted by TomDavidson (Member # 124) on :
 
Really? What was the problem?
 
Posted by Nighthawk (Member # 4176) on :
 
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"...
 
Posted by Lyrhawn (Member # 7039) on :
 
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.
 
Posted by Blayne Bradley (Member # 8565) on :
 
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.
 


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