I would really appreciate help from anyone who can tell me how to permit a user to enter an end date, and have it accepted by the system.

Currently a customer can enter a start date, but if they enter an end date that is in the same month as the start date, the system reports "select an end date greater than current date", which is ridiculous considering that any date after the start date is greater than the start date.

I look forward to any help I can get.

Ric

Hi
I post here one example of date validation using javascript

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>Start date:</td>
    <td colspan="2">
      <input type="text" name="txt_start" id="txt_start"  style="width:200px"  onBlur="Check_date();"/>
    </td>
  </tr>
  <tr>
    <td>End date:</td>
    <td colspan="2">
      <input type="text" name="txt_end" id="txt_end" style="width:200px" onBlur="Check_date();" />
    </td>
  </tr>
 </table>
<script type="text/javascript">
function Check_date()
{
	
		var start = new Date (document.getElementById('txt_start').value);
		var end = new Date (document.getElementById('txt_end').value);
		if(start>end)
		{
		
				alert("start date not greatewr than end date")		
				return false;
		
		}
		else
		{
					return true;
		}

}
</script>

May be this code helpfull to you.
Thanks

Can we see the code that generates that error? Some simple logic changes should fix the problem.

Thanks for your erply Keith. Because I cant code, I am not sure which part of the code actually tells the user that they can't post.

Here is part of the code from the offending page, if you need more, please let me know.

<td width="78%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0" height="244">
              <tr>
                <td width="7%" height="23" bgcolor="#FFFFFF" ><p align="center"></p></td>
                <td width="93%" height="23" colspan="2" bgcolor="#FFFFFF" ><b><font size="3" face="Century Gothic" color="#000000">To Post your specials</font></b> </td>
              </tr>
              <tr>
                <td width="7%" height="26" bgcolor="#FFFFFF"></td>
                <td width="6%" height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td width="87%" height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Click on the category drop down box, and select your category</font></b></td>
              </tr>
              <tr>
                <td width="7%" height="26" bgcolor="#FFFFFF"></td>
                <td width="6%" height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td width="87%" height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Select a sub-category</font></b></td>
              </tr>
              <tr>
                <td width="7%" height="26" bgcolor="#FFFFFF"></td>
                <td width="6%" height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td width="87%" height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Enter a start date</font></b></td>
              </tr>
              <tr>
                <td height="26" bgcolor="#FFFFFF"></td>
                <td height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Enter an end date</font></b></td>
              </tr>
              <tr>
                <td height="26" bgcolor="#FFFFFF"></td>
                <td height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Enter the number of items you wish to post</font></b></td>
              </tr>
              <tr>
                <td width="7%" height="26" bgcolor="#FFFFFF"></td>
                <td width="6%" height="26" bgcolor="#FFFFFF"><p align="center"><img border="0" src="pics/bullet1.gif"></td>
                <td width="87%" height="26" bgcolor="#FFFFFF"><b><font face="Verdana" size="2" color="#000000">Click on the Next&gt; button to go the page to enter  details of your special, or special offer</font></b></td>
              </tr>
              <tr>
                <td width="100%" height="21" colspan="3" bgcolor="#FFFFFF"></td>
              </tr>
              <tr bgcolor="#6666ff">
                <td width="100%" height="21" colspan="3"><p align="center"><font face="Comic Sans MS" color="#FFFFFF" size="3">Post Your Specials</font></td>
              </tr>
			  
<script language="javascript" type="text/javascript">
function chkAgreement()
{
	
	if (document.Form1.catName.value=="a") 
	{
		alert( "Please Select the category");
		document.Form1.catName.focus();
		return false;
	}
	if (document.Form1.subCatName.value=="a") 
	{
		alert( "Please Select the Sub category");
		document.Form1.subCatName.focus();
		return false;
	}
		return getCalendarDate();
		return true; 

	/*if (document.Form1.dayst.value=="") 
	{
		alert( "Please Select the start date");
		document.Form1.dayst.focus();
		return false;
	}
	if (document.Form1.monthst.value=="") 
	{
		alert( "Please Select the start month");
		document.Form1.monthst.focus();
		return false;
	}
	if (document.Form1.yearst.value=="") 
	{
		alert( "Please Select the start year");
		document.Form1.yearst.focus();
		return false;
	}
	if (document.Form1.item.value=="") 
	{
		alert( "Please enter the no of item");
		document.Form1.item.focus();
		return false;
	}*/


	
	 //return getCalendarDate();
	 
}
var isIE = document.all?true:false; 
var isNS = document.layers?true:false;
var invalid = " "; 
// Invalid character is a space 
function onlyDigits(e,decReq) 
	{ 
var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target; 
var isNum = (key > 47 && key < 58) ? true:false; 
var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false; window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key; e.which = (!isNum && !dotOK && isNS) ? 0:key; 
return (isNum || dotOK); 
} 
</script>
<script language="javascript" type="text/javascript">

  function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }


 var year=document.Form1.yeared.value;
 var month=document.Form1.monthed.value;
 var day=document.Form1.dayed.value;

 var chdate=year+month+day;


var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()

//document.write("Today's date is: ")

if(themonth<10)
{
	themonth="0"+themonth;
}



var curdate=theyear+"."+themonth+"."+thetoday;

var curdate1=curdate.replace(".","");

var curdate2=curdate1.replace(".","");

//alert(curdate2);

//alert(chdate);

 if(chdate<=curdate2)
	{
	
	
	alert( "Your System Date is:"+curdate2+" .Please Select the end date greater than current date");
	document.Form1.dayed.focus();
	return false;
	
	
	
	}


   /*var dateString = monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;*/

	//if (document.Form1.yeared.value<=year)
	// {
		//if (document.Form1.monthed.value<=monthnumber)
		// { 
		//	if (document.Form1.dayed.value<=monthday)
			 // {
				//alert( "Please Select the end date greater than current date");
				//document.Form1.dayed.focus();
				//return false;
			  //}
		 // alert( "Please Select the end month greater than current month");
		  //document.Form1.monthed.focus();
		 // return false;
		//}
	  //alert( "Please Select the end Year greater than current Year");
	 // document.Form1.yeared.focus();
	 // return false;
	// }
    
} // function getCalendarDate()

</script>
              <tr>
                <td width="100%" height="21" colspan="3"><!--<form name="Form1" method="POST" action="post2.php" onSubmit="return getValid()" onSubmit="return document.MM_returnValue;">-->
				<form name="Form1" method="POST" action="post2.php">
				
                    <table border="0" width="100%" cellspacing="0" cellpadding="0" >
                      <tr bgcolor="#E1E1FF">
                        <td height="26" colspan="3"><font face="Verdana" size="3"><b>Step 1 of 2 </b></font></td>
                      </tr>
                      <tr bgcolor="#FFFFFF">
                        <td width="46%" height="26"><p align="left"><font color="#000000" size="2" face="Verdana"> Your Category</font></p></td>
                        <td width="1%" height="26"><p align="left"><font face="Verdana" size="2" color="#FF0000">:</font></td>
                        <td width="53%" height="26"><div align="left"><font size=2>&nbsp;
                            <select name="catName" onChange="showCustomer(this.value)">
                                <option value="a">Select a category</option>
                                <?
								$i=0;
								
								while($s[$i] != NULL)
								{
								$sql = "SELECT * FROM category_master where id='$s[$i]'";
								//echo $sql;

								$res_1= mysql_query($sql) or die('$sql<br>Error---->'.mysql_error());
								$rr=mysql_fetch_row($res_1);
								if($i==0)
									{
								?>
                                <option value="<?=$s[$i]?>">
                                <?=$rr[1]?>
                                </option>
                                <?
									}
								else
									{?>
                                <option value="<?=$s[$i]?>">
                                <?=$rr[1]?>
                                </option>
                                <?}

								$i++;
								}
								?>
                            </select>
                        </font><font size="2" face="Verdana" color="#FF0000">*</font></div></td>
                      </tr>
                      <tr bgcolor="#E1E1FF">
                        <td width="46%" align="right" height="26"><div align="left"><font color="#000000" size="2" face="Verdana">Select Your sub Category</font></div></td>
                        <td width="1%" height="26" align="center"><div align="left"><font face="Verdana" size="2" color="#FF0000">:</font></div></td>
                        <td width="53%" height="26" id="txtHint"><div align="left"><font size=2>&nbsp;
                            <select name="subCatName">
                                <option value="a">Select a sub-category....</option>
                            </select>
                        </font><font size="2" face="Verdana" color="#FF0000">*</font> </div></td>
                      </tr>
                      <tr bgcolor="#FFFFFF">
                        <td width="46%" align="right" height="26"><div align="left"><font face="Verdana" size="2" color="#000000">Start Date</font></div></td>
                        <td width="1%" height="26" align="center"><div align="left"><font face="Verdana" size="2" color="#FF0000">:</font></div></td>
                        <td nowrap="nowrap" class="booknowfield">&nbsp;
						 <?php
								$dayst = $monthst=$yearst = "";
								$dayst = "<select name='dayst'>\r\n";
							for($i=1;$i<=31;$i++){
							   if($i<10)
									$dayst.="<option value='0$i'>0$i</option>\r\n";
							   else
									$dayst.="<option value='$i'>$i</option>\r\n";
							}
								$dayst.= "</select>\r\n";
							
							//////////////
							///////////
						
							$monthst = "<select name='monthst'>\r\n";

						for($i=1;$i<=12;$i++)
						   if($i<10)
								$monthst.="<option value='0$i'>0$i</option>\r\n";
						   else
								$monthst.="<option value='$i'>$i</option>\r\n";
							
							$monthst.= "</select>\r\n";
						
							///////////////
						
							$yearst.= "<select name='yearst'>\r\n";
							for($i=Date(Y);$i<=Date(Y)+4;$i++)
									$yearst.="<option value='$i'>$i</option>\r\n";
							$yearst.= "</select>\r\n";
							
							 echo $dayst."&nbsp;/&nbsp;".$monthst."&nbsp;/&nbsp;".$yearst;

				 ?>					
					
                          <div align="left"></div></td>
                      </tr>
                      <tr bgcolor="#E1E1FF">
                        <td width="46%" align="right" height="26"><div align="left"><font face="Verdana" size="2" color="#000000">End Date</font></div></td>
                        <td width="1%" height="26" align="center"><div align="left"><font face="Verdana" size="2" color="#FF0000">:</font></div></td>
                        <td nowrap="nowrap" class="booknowfield">&nbsp;
								 <?php
								$dayed = $monthed = $yeared = "";
								$dayed = "<select name='dayed'>\r\n";
							for($i=1;$i<=31;$i++){
							   if($i<10)
									$dayed.="<option value='0$i'>0$i</option>\r\n";
							   else
									$dayed.="<option value='$i'>$i</option>\r\n";
							}
								$dayed.= "</select>\r\n";

							//////////////
							///////////
							
							$monthed = "<select name='monthed'>\r\n";

							for($i=1;$i<=12;$i++)
							if($i<10)
								$monthed.="<option value='0$i'>0$i</option>\r\n";
							else
								$monthed.="<option value='$i'>$i</option>\r\n";

							$monthed.= "</select>\r\n";

							///////////////
								
							$yeared.= "<select name='yeared'>\r\n";
							for($i=Date(Y);$i<=Date(Y)+4;$i++)
									$yeared.="<option value='$i'>$i</option>\r\n";
							$yeared.= "</select>\r\n";

							 echo $dayed."&nbsp;/&nbsp;".$monthed."&nbsp;/&nbsp;".$yeared;

						 ?>
                          <div align="left"></div></td>
                      </tr>

It would be great if you or someone can help.

Thanks in advance


Ric

I am enclosing a pic of the actual problem in which the chosen dates are displayed, and the error box also displayed.

Cheers


Ric

ps. I don't know if the attachment is uploaded, please let me know if it didn't.

This article has been dead for over six months. Start a new discussion instead.