Disable submit data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    Disable submit data

    //the code
    [HTML]<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>TEST form</title>
    <script type="text/javascript">
    function check()
    {
    txt1= document.getEle mentById("usern ame")
    txt2= document.getEle mentById("passw ord")
    if(document.get ElementById("us ername").value= ="")
    {
    alert(document. getElementById( "username").nam e);

    }
    if(document.get ElementById("pa ssword").value= ="")
    {
    alert(document. getElementById( "password").nam e);

    }
    return true
    }
    </script>
    </head>
    <body>
    <div align="right">
    <form id="form1" name="form1" method="post" action="test-2.php" onsubmit="retur n check()">
    <label> Username:
    <input type="text" name="username" id="textfield" />
    <br />
    Password:
    <input type="text" name="password" id="textfield2 " />
    <br />
    <input type="submit" name="Login" id="Login" value="Submit" />
    </label>
    </form>
    </div>
    </body>
    </html>[/HTML]
    in this code i need to disable the form to Submit the data to another page and how to simplify the code without using if statement many times
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You want to stop the form submission. Add "return false" after the alerts.

    Comment

    Working...