<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>XYZ Travels Pvt Ltd.</title>
        <script type="text/javascript"  language="javascript">
        function a(){
           var x = document.forms.frm1.UserID.value;
           var y = document.forms.frm1.Pass.value;

           if(x=="" || y=="")
               {
                alert("Required Field cannot be left Blank");
                if(x!="")
                    {
                        document.forms.frm1.Pass.focus();
                    }
                 else{document.forms.frm1.UserID.focus();}
               }
            else
            {
               document.forms.frm1.action("Reg.jsp");
            }
        }

    </script>
    </head>
    <link href="projstyle.css" rel="stylesheet" type="text/css" />
    
    <body><font color="white">
            <form method="post" name="frm1">
        Login : <input name="UserID" type="text"/>
        <br>
        Password : <input name="Pass" type="password" maxlength="18"/>
        <br>
        <input name="btn1" type="button" onclick="a();"/>
        <a href="Reg.jsp">Register Now!</a>
    </form></font></body>
</html>

how do i cause the form to post to another page? Am I doing it correct? I want this to happen ONLY if validation passes.

Hi Alex,

Please check the sample below:

<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
</script>
</head>

<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>

</html>

Much more cleaner than my code. Thanx!

Nicely Explained

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.