SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form level validation does not work in firefox

    I'm learning javascript and doing some form-level validation testing. My validation code works in IE but not firefox. Firefox justs submits. I've done the following:
    1. Searched this forum for any relevant postings.
    2. Validated my xhtml file on W3C.
    3. No error messages in Firefox Error Console.
    4. Installed Firebug but received no errors.
    5. Checked to ensure Javascript is enabled in Firefox.

    I just can't figure it out. The code to me seems valid. I appreciate any assistance. I'm new at forums so if my posting is violating any rules please let me know.


    Here is my script code...

    function loadForm ( )
    {
    document.getElementById("name").value = "";
    document.getElementById("name").focus ( );
    }

    function resetForm ( )
    {
    document.getElementById("name").focus ( );
    document.getElementById("message").innerText = "";
    }[/HIGHLIGHT]function validateForm ( )
    {
    var error = true;
    document.getElementById("message").innerText = "";

    if (!document.getElementById("name").value)
    {
    document.getElementById("message").innerText = "This field is required";
    error = false;
    }

    return error;
    }


    And here is the xhtml...

    <html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type = "text/javascript" src = "scripts.js"></script>
    </head>

    <body onload = "loadForm ( )">
    <form id = "form" onsubmit = "return validateForm ( )" action
    = "confirm.html" method = "post">
    <table>
    <tr>
    <td>Name</td>
    <td><input type = "text" id = "name" name = "name" /></td>
    <td><span id = "message"></span></td>
    </tr>
    </table>
    <p>
    <input type = "submit" name = "button" value = "Submit" />
    <input type = "reset" name = "reset" value = "Reset" onclick
    = "resetForm ( )" />
    </p>
    </form>
    </body>
    </html>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,182
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    submit

    Hi mikayla, welcome to the forums,
    Your problem may be similar to this one http://www.sitepoint.com/forums/showthread.php?t=501400 (a bit lengthy perhaps, but skim ahead to the last few posts)
    P.S. Please edit your post and put the code inside bbtags, it's much easier to read that way.


Bookmarks

Posting Permissions

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