Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    235
    Thanks
    6
    Thanked 21 Times in 20 Posts

    Beginner javascript - not working? :/

    http://udjamaflip.com/test.html is the url

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script type="text/javascript">
    <!--
    
    function validate_form ( )
    {
        valid = true;
    
        if ( document.contact_form.name.value == "" )
        {
            alert ( "Please fill in the 'Your Name' box." );
            valid = false;
        }
    
        return valid;
    }
    
    //-->
    </script>
    
    
    </head>
    
    <body>
    
    
    <form name="contact_form" method="post"action="test.html" onsubmit="return validate_form();">
    
    	name: <input type="text" name="name" />
        <br />
        age: <input type="text" name="age" />    
        <br /><br />
        <input type="submit" value="submit" name="submit" />
    
    </form>
    
    </body>
    </html>
    Is the code

    Anyone able to tell me whats wrong? it should be very basic and working :/
    Last edited by udjamaflip; 08-26-2008 at 01:38 PM.
    Andrew Sharman
    Web designer, developer and programmer.

    If you found my post helpful, why not give thanks! :)

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    document.contact_form.myname.value
    Code:
    <input type="text" name="myname" />
    Never use an attribute name to name a control to confuse the DOM ( woops .. how can I express that ? )
    Last edited by abduraooft; 08-26-2008 at 01:50 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by abduraooft View Post
    [
    Never use an attribute name to name a control to confuse the DOM ( woops .. how can I express that ? )
    To develop that point:-

    In Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an element name or ID. You should also avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/attributes such as 'name' or 'id' or 'value' or 'checked' or 'submit' or 'replace' or 'parseInt'.


    A child of five would understand this. Send someone to fetch a child of five.
    Groucho Marx

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    ...and you'd get a clear picture if you just put alerts like
    Code:
    alert(document.contact_form.name);
    alert(document.contact_form.myname); //after changing the name of input
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •