PDA

View Full Version : problem with form submission



nischalinn
05 Jun 2011, 02:53 PM
My form is:
*****************************
<form name="RegistrationForm" id="form1" method="post">
<table border="0">
<tr>
<td>User_Id</td>
<td><input type="text"name="User_Id" id="User_Id" /></td>
</tr>

<tr>
<td>Date</td>
<td><input type="text"name="Date" id="Date" /></td>
</tr>

<tr>
<td><input type="image" src="submit.gif" onclick="SubmitForm()"/></td>
****************************************************************
Now I want to check if both of the fields are entered before pressing the Submit button.
Also if one of the field is not completed before submitting the form, it will generate an error message. and the user has to fill the left fields of the form.
but it must restore the previous filled values.
I've tha js code as:
*******************************************
function SubmitForm()
{
if( (document.getElementById('User_Id').value=="") || (document.getElementById('Date').value=="") )

alert("please complete the form");
return false;
}

else return true;
}
*********************************************
But this code wont restore the previous values. I've to re-enter all the values. How can I write js code for this problem??

MarPlo
09 Jun 2011, 07:43 AM
Hy,
Try with this code:


<form name="RegistrationForm" action="" id="form1" method="post" onsubmit="return SubmitForm();">
<table border="0">
<tr>
<td>User_Id</td>
<td><input type="text"name="User_Id" id="User_Id" /></td>
</tr>
<tr>
<td>Date</td>
<td><input type="text"name="Date" id="Date" /></td>
</tr>
<tr>
<td><input type="image" src="submit.gif" /></td></table></form>

<script type="text/javascript"><!--
function SubmitForm()
{
if( (document.getElementById('User_Id').value=="") || (document.getElementById('Date').value=="") ) {

alert("please complete the form");
return false;
}
else return true;
}
--></script>