Posts: 850
Name: Matt Pealing
Location: England, north west
|
Ive been on the brink of ripping my hair out from trying to learn Javascript lately. Programming in general I don't have much trouble with, but I seem to have the wierdest of problems when coding with this.
I didn't think I would have much trouble getting to grips with it as it looks quite similar to other languages which Ive learnt in the past. But I cant even seem to get it to perform some simple form validation.
Heres some code Ive been using:
Code:
function validateForm()
{
var name = document.getElementById('name');
var email = document.getElementById('email');
if((name.value == null)||(name.value == ""))
{
alert("Please enter your name.");
return false;
}
if((email.value == null)||(email.value == ""))
{
alert("Please enter your email.");
return false;
}
else
{
return true;
}
}
The name part works fine, but the email bit does nothing. [I've even tested it by commenting out the name section, and it still doesnt work].
Not only that but I think the main reason its so hard to fix errors is because you have to manually sift through the code to find whats wrong with it. Ive tried using JSLint and I cant figure out what its talking about when it comes to errors.
I think the best bet would probably be to buy a book on it...
|