0
<%@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.

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by stanleyben
0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.