Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript issue

Options
2»

Comments

  • Registered Users Posts: 191 ✭✭jjjade


    oh ok like this

    [HTML]

    <script type ="text/javascript">
    //<![CDATA[
    function abc()
    {
    alert("2");


    if (cardForm.eMail.value.length < 6)
    {
    alert("Failed enter card num correctly");
    return false;

    }

    else if (cardForm.pHone.value.length < 6)
    {
    alert("Failed enter card num correctly");
    return false;

    }

    else if (cardForm.username.value.length < 6)
    {
    alert("Failed enter card num correctly");
    return false;

    }

    else if (cardForm.password.value.length < 6)
    {
    alert("Failed enter card num correctly");
    return false;

    }
    else
    {
    alert("success");
    document.location="Login.xhtml";
    return true;

    }

    }
    //]]>
    </script>
    </head>


    <body>
    <form id="cardForm" onsubmit="return abc();" action="cc_details.xhtml">

    <p>Registration Form</p>

    <p><label accesskey="e">Email:<input type="text" id="eMail"/></label></p>

    <p><label accesskey="p">Phone Number:<input type="text" id="pHone"/></label></p>

    <p><label accesskey="u">Username:<input type="text" id="username"/></label></p>

    <p><label accesskey="w">Password:<input id="password" type="password" /></label></p>

    <p><input type="submit" value="Submit"/>
    <input type="reset" value="Clear"/></p>
    <input type="button" value="test" onclick="abc();"/>

    </form>

    </body>
    </html>

    [/HTML]


    can some1 help :(


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    That's much better :)

    That code seems to work fine for me using Chrome, Firefox and IE.


  • Registered Users Posts: 191 ✭✭jjjade


    it works but if you dont enter in details it goes straight to the action on the form without entering the java.... doesnt matter luck of a miracle its working

    what i did i have no clue

    thank you :D


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    You had HTML comments in your earlier JavaScript. That probably caused the script to fail, and therefore the form was submitted.

    A HTML comment looks like this:
    [html]<!-- hide me -->[/html]
    JavaScript comments look like:
    // one line comment
    /*
    this is acomment
     over a few lines
    */
    


Advertisement