Results 1 to 3 of 3

Thread: onSubmit dont want to clear form

  1. #1
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default onSubmit dont want to clear form

    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

    HTML Code:
    <!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>
    Last edited by vineet; 03-22-2009 at 05:45 AM. Reason: code

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    see if this works:
    Code:
    <!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>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Jun 2008
    Posts
    114
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default onsubmit

    hi Master_script_maker

    thanks. It works perfect.

    but it needs cookies to be enabled on browser.

    vineet

    Quote Originally Posted by Master_script_maker View Post
    see if this works:
    Code:
    <!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>

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •