.hack//GU 0 Report post Posted May 17, 2006 I make this function: <script language="JavaScript" type="text/javascript"> function validFormUse(passF) { if(passF.user.value == "") return false; if(passF.pass.value == "") return false; return true }</script> I want to make : if(passF.user.value == "") return false; like this: if(passF.user.value == ""){ alert("FALSE"); return false;} but, it doesn;t work. Why? I use the brackets and it doens't work. only if it doesn't use brackets it is fully operational. anybody know what's wrong? Notice from BuffaloHELP: Please use correct bbcode for posting codes. Share this post Link to post Share on other sites
beeseven 0 Report post Posted May 17, 2006 Without brackets it would have the alert then always return false since it would only treat the alert as part of the if statement. I see no reason why it wouldn't work the second way, though. Share this post Link to post Share on other sites
.hack//GU 0 Report post Posted May 19, 2006 yes, in the first code it return false if the brackets is empty. But, what I mean is when I use brackets, well is pops up the window (alert), but the browser goes through the action in the form, means it doesn't return false. So, in short, I can only have 1 command after 'if' and cannot use any brackets. Is that possible for mistake? thanks in advance Share this post Link to post Share on other sites
hyuken 0 Report post Posted June 16, 2006 <script language="JavaScript" type="text/javascript">function validFormUse(passF){if(passF.user.value == "") return false;if(passF.pass.value == "") return false;return true}</script> If iam not mistake...you're going to check 2 element user and pass that should not be submitteduntil both is filled with a string...how about using this code :<form .... onSubmit="if (validFormUse('blablabla')) this.submit(); else return false;">......</form><script language="JavaScript" type="text/javascript">function validFormUse(passF){ if (passF.user.value == "") { alert('Please entry your user name'); passF.user.focus(); return false; } else if (passF.pass.value == "") { alert('Please entry your password'); passF.pass.focus(); return false; } else ruturn true;}</script> i've add an alert() and focus() function so it would have information, andpointing to `FALSE` element. so user can type without moving their mice.i hope it could help you. Share this post Link to post Share on other sites
dyknight 0 Report post Posted July 1, 2006 It is probably syntax. Here is what I suggest:Open up Firefox, go to tools-> Javascript console and hit "Clear".Then open your page and test the script.Then open up the Javascript console again and see what are the errors.Hope this helps. Paste the error reports here.Anyway, Javascript uses soft-typing. So if (sth == ""){} is the same asif (sth){} because null translates to false. Share this post Link to post Share on other sites