Jsp Form Not Getting Submitted
what I am trying to do here is in the form if none of the field is entered then alert is shown and if even one of the field is entered, the form is submitted.and i am using javasc
Solution 1:
Change the type of the search button to "submit" (type button does not submit a form), and it will submit the form. Or you can do:
document.form["report"].submit();
inside the checkemptyreport()
function.
Solution 2:
Look at this example:
Javascript:
window.onsubmit = function()
{
var firstname = document.getElementById("FirstName").value;
var lastname = document.getElementById("LastName").value;
var district = document.getElementById("District").value;
if(firstname == "" && lastname=="" && district=="")
{
alert("Fill in at least one");
returnfalse;
}
else
{
alert(2);
//document.forms["report"].submit();document.form["report"].action = "/reportbeanservlet";
//document.location = "reportbeanservlet";returntrue;
}
}
Markup:
<form method="POST" name="report"id="reportbean">
<input type="text" name="FirstName"id="FirstName" />
<input type="text" name="LastName"id="LastName" />
<input type="text" name="District"id="District" />
<input type="submit" value="Submit" />
</form>
This is of course a smaller version of your code, but as @tomor sugested, you can do it with a submit button, and capturate the onsubmit
event of your form.
jsFiddle: http://jsfiddle.net/hescano/xZEbH/
Post a Comment for "Jsp Form Not Getting Submitted"