PDA

View Full Version : onSubmit dont want to clear form



vineet
03-22-2009, 04:42 AM
hi all

i have two date fields which i dont want to get clear after submitting.

actually i have two buttons which perform different functions like one button will show records and if records are

corect then on click of second buton the email will be send but will work only if both my fields are filled.

so in this case the user has to enter informtaion in both fields again and again. thats why i dont want the fields

information entered to be clear on submit.

vineet



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
function validate()
{

if(document.form1.datef.value=='')
{
alert("enter first date");
document.form1.datef.focus();
return false;
}
if(document.form1.dates.value=='')
{
alert("enter second date");
document.form1.dates.focus();
return false;
}
}
</script>
</head>
<body>
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return

validate()">
<table align="center" cellpadding="4" cellspacing="0">

<tr>
<td height="30"><table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="192">Select first date </td>
<td>&nbsp;</td>
<td width="190">Select second date </td>
</tr>
<tr>
<td><input type="text" name="datef" id="datef" /></td>
<td width="27">to</td>
<td><input type="text" name="dates" id="dates" /></td>
<td width="191"><input type="submit" name="record" value="see records" />
<input type="submit" name="submit" value="send email" /></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>

Master_script_maker
03-22-2009, 07:57 PM
see if this works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
function validate()
{

if(document.form1.datef.value=='')
{
alert("enter first date");
document.form1.datef.focus();
return false;
}
if(document.form1.dates.value=='')
{
alert("enter second date");
document.form1.dates.focus();
return false;
}
remember();
}
function remember() {
createCookie("date", document.form1.datef.value+":"+document.form1.dates.value);
}

function retrieve() {
var val = readCookie("date");
if(val!=null) {
var s=val.split(":");
document.form1.datef.value=s[0];
document.form1.dates.value=s[1]
}
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
</head>
<body onload="retrieve()">
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return validate()">
<table align="center" cellpadding="4" cellspacing="0">

<tr>
<td height="30"><table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="192">Select first date </td>
<td>&nbsp;</td>
<td width="190">Select second date </td>
</tr>
<tr>
<td><input type="text" name="datef" id="datef" /></td>
<td width="27">to</td>
<td><input type="text" name="dates" id="dates" /></td>
<td width="191"><input type="submit" name="record" value="see records" />
<input type="submit" name="submit" value="send email" /></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>

vineet
03-23-2009, 03:46 AM
hi Master_script_maker

thanks. It works perfect.

but it needs cookies to be enabled on browser.

vineet


see if this works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
function validate()
{

if(document.form1.datef.value=='')
{
alert("enter first date");
document.form1.datef.focus();
return false;
}
if(document.form1.dates.value=='')
{
alert("enter second date");
document.form1.dates.focus();
return false;
}
remember();
}
function remember() {
createCookie("date", document.form1.datef.value+":"+document.form1.dates.value);
}

function retrieve() {
var val = readCookie("date");
if(val!=null) {
var s=val.split(":");
document.form1.datef.value=s[0];
document.form1.dates.value=s[1]
}
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
</head>
<body onload="retrieve()">
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return validate()">
<table align="center" cellpadding="4" cellspacing="0">

<tr>
<td height="30"><table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="192">Select first date </td>
<td>&nbsp;</td>
<td width="190">Select second date </td>
</tr>
<tr>
<td><input type="text" name="datef" id="datef" /></td>
<td width="27">to</td>
<td><input type="text" name="dates" id="dates" /></td>
<td width="191"><input type="submit" name="record" value="see records" />
<input type="submit" name="submit" value="send email" /></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>