Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How confusing is Javascript?!?
Old 12-09-2007, 02:31 PM How confusing is Javascript?!?
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
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...
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 12-09-2007, 04:30 PM Re: How confusing is Javascript?!?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
getElementById shouldn't really be used with form elements and values

try
document.forms["form_name"].elements["input_name"].value
or
document.form_name.input_name.value

For debugging use the Firefox javascript console.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to How confusing is Javascript?!?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17366 seconds with 12 queries