external js fiie not working when trying to validate a jsp form

181 Views Asked by At

the jsp page containing form

function formValidation()
{

    var fname= document.form1.first_nm;


<form name="form1" onsubmit="return formValidation()" method="post">

First Name:<input type="text" name="first_nm" /><br>

My jsp page:

index.jsp

The jsp page contains the form on using the onsubmit event it is not loadingthe extyernal js file. please help. I am not able to get where I am going wrong.

1

There are 1 best solutions below

0
On
<script type="text/javascript">
function FormCheck()
{
  var x = document.forms["form1"]["first_nm"].value;
  var y = document.forms["form1"]["last_nm"].value;
    if (x == null || x == "") {
        alert("FirstName must be filled out");
        return false;
    }
     if (y == null || y == "") {
        alert("LastName must be filled out");
        return false;
    }
}
</script>

I am Assuming that your Jsp page is Something like this

<html:form action="form1" name="form1" onsubmit="return FormCheck();" method="POST">    

First Name:<input type="text" name="first_nm" /><br>
Last  Name:<input type="text" name="last_nm" /><br>
.
.
.

</html:form>