![]() |
simple validation issue
Hi,
I learning javascript and now doing a simple validation however i'm coming across an issue. See code below Html Code:
<form name="loginsubmit" method="post" action="adproperties.html"></form>Code:
<script>Help would be appreciated. |
The semicolon in Javascript is used to end a statement. So with the semicolon at the end of the if statement you are already closing the if statement. So no matter what the condition in the if statement is, the next line(s) will always be executed.
This is the correct syntax for a simple if statement (one statement) Code:
if(condition)Code:
if(condition) { |
Quote:
Note that even a single space will pass the validation if(document.loginsubmit.usernameform == '' ) { You should always strip leading and trailing spaces from all user input:- Code:
x = x.replace(/^\s+|\s+$/g,""); |
Quote:
Code:
|
You are missing the closing right brace } for the left brace { that follow the if.
You are also missing the left brace { for beginning the function. Code:
function loginvalidation() |
Quote:
Thank you. Code:
if(document.loginsubmit.usernameform.value == " ) |
LOL! DOH on all of us for missing that! Good catch.
|
oh my ... the .value totally escaped me. There were already more than enough simpler problems :-)
|
| All times are GMT +1. The time now is 12:28 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.