Forums

This topic is locked

This may come in Very Handy

Posted 26 Sep 2002 02:05:18
1
has voted
26 Sep 2002 02:05:18 Gary Whittle posted:
Hi folks.

I would like to say thanks for all the help yesterday with my SUM and BETWEEN SQL queries.

I have been working on an life insurance managegment system and have created a script which generates two dates in SQL "datetime" format from a date dropdown list.

The script pre-populates two form fields (startdate and enddate) and the form uses the post method to get results on the ASP page, which generates records between "startdate and endate".

Anyway it may be useful to you guys, I paste the entire body below, it should simply "run" if you paste into a standard HTML document.

Of course you will have to configure your ASP page to accept the values "startdate" and "enddate", or you will have to update the values on the script.

If you dont use it for the "get" method, it may come in handy for a timestamp generator.

The datebuild is triggered when your mouse presses the "generate" button.

Let me know what you guys think.

Im a beginner with JavaScript so any criticism welcome <img src=../images/mxzone/forum/icon_smile.gif border=0 align=middle>

Gary.


YOU MAY WANT TO SET THE TWO FORM ELEMENTS, "stardate" and "enddate" to type="hidden", so the user cannot manipulate. I have left visible to show what the script does.

Here is the HTML of my page: (runs as it is, just save the below as an HTML file):


<font color=red>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;SQL Date Builder&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body bgcolor="#EBEBEB"&gt;
&lt;form name="form1" method="get" action="results.asp"&gt;
&lt;table width="300" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000"&gt;
&lt;tr&gt;
&lt;td bgcolor="#FFFFFF"&gt;&lt;table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#F2F2F2"&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td width="33%"&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Day:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Month:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Year:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="day" id="select12" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="00"&gt;start&lt;/option&gt;
&lt;option value="01"&gt;01&lt;/option&gt;
&lt;option value="02"&gt;02&lt;/option&gt;
&lt;option value="03"&gt;03&lt;/option&gt;
&lt;option value="04"&gt;04&lt;/option&gt;
&lt;option value="05"&gt;05&lt;/option&gt;
&lt;option value="06"&gt;06&lt;/option&gt;
&lt;option value="07"&gt;07&lt;/option&gt;
&lt;option value="08"&gt;08&lt;/option&gt;
&lt;option value="09"&gt;09&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="11"&gt;11&lt;/option&gt;
&lt;option value="12"&gt;12&lt;/option&gt;
&lt;option value="13"&gt;13&lt;/option&gt;
&lt;option value="14"&gt;14&lt;/option&gt;
&lt;option value="15"&gt;15&lt;/option&gt;
&lt;option value="16"&gt;16&lt;/option&gt;
&lt;option value="17"&gt;17&lt;/option&gt;
&lt;option value="18"&gt;18&lt;/option&gt;
&lt;option value="19"&gt;19&lt;/option&gt;
&lt;option value="20"&gt;20&lt;/option&gt;
&lt;option value="21"&gt;21&lt;/option&gt;
&lt;option value="22"&gt;22&lt;/option&gt;
&lt;option value="23"&gt;23&lt;/option&gt;
&lt;option value="24"&gt;24&lt;/option&gt;
&lt;option value="25"&gt;25&lt;/option&gt;
&lt;option value="26"&gt;26&lt;/option&gt;
&lt;option value="27"&gt;27&lt;/option&gt;
&lt;option value="28"&gt;28&lt;/option&gt;
&lt;option value="29"&gt;29&lt;/option&gt;
&lt;option value="30"&gt;30&lt;/option&gt;
&lt;option value="31"&gt;31&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="month" id="select13" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="00"&gt;start&lt;/option&gt;
&lt;option value="01"&gt;01&lt;/option&gt;
&lt;option value="02"&gt;02&lt;/option&gt;
&lt;option value="03"&gt;03&lt;/option&gt;
&lt;option value="04"&gt;04&lt;/option&gt;
&lt;option value="05"&gt;05&lt;/option&gt;
&lt;option value="06"&gt;06&lt;/option&gt;
&lt;option value="07"&gt;07&lt;/option&gt;
&lt;option value="08"&gt;08&lt;/option&gt;
&lt;option value="09"&gt;09&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="11"&gt;11&lt;/option&gt;
&lt;option value="12"&gt;12&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="year" id="select14" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="0000"&gt;start&lt;/option&gt;
&lt;option value="2002"&gt;2002&lt;/option&gt;
&lt;option value="2003"&gt;2003&lt;/option&gt;
&lt;option value="2004"&gt;2004&lt;/option&gt;
&lt;option value="2005"&gt;2005&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&nbsp;&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Day:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Month:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Year:&lt;/font&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="day2" id="select15" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="31"&gt;end&lt;/option&gt;
&lt;option value="01"&gt;01&lt;/option&gt;
&lt;option value="02"&gt;02&lt;/option&gt;
&lt;option value="03"&gt;03&lt;/option&gt;
&lt;option value="04"&gt;04&lt;/option&gt;
&lt;option value="05"&gt;05&lt;/option&gt;
&lt;option value="06"&gt;06&lt;/option&gt;
&lt;option value="07"&gt;07&lt;/option&gt;
&lt;option value="08"&gt;08&lt;/option&gt;
&lt;option value="09"&gt;09&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="11"&gt;11&lt;/option&gt;
&lt;option value="12"&gt;12&lt;/option&gt;
&lt;option value="13"&gt;13&lt;/option&gt;
&lt;option value="14"&gt;14&lt;/option&gt;
&lt;option value="15"&gt;15&lt;/option&gt;
&lt;option value="16"&gt;16&lt;/option&gt;
&lt;option value="17"&gt;17&lt;/option&gt;
&lt;option value="18"&gt;18&lt;/option&gt;
&lt;option value="19"&gt;19&lt;/option&gt;
&lt;option value="20"&gt;20&lt;/option&gt;
&lt;option value="21"&gt;21&lt;/option&gt;
&lt;option value="22"&gt;22&lt;/option&gt;
&lt;option value="23"&gt;23&lt;/option&gt;
&lt;option value="24"&gt;24&lt;/option&gt;
&lt;option value="25"&gt;25&lt;/option&gt;
&lt;option value="26"&gt;26&lt;/option&gt;
&lt;option value="27"&gt;27&lt;/option&gt;
&lt;option value="28"&gt;28&lt;/option&gt;
&lt;option value="29"&gt;29&lt;/option&gt;
&lt;option value="30"&gt;30&lt;/option&gt;
&lt;option value="31"&gt;31&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="month2" id="select16" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="12"&gt;end&lt;/option&gt;
&lt;option value="01"&gt;01&lt;/option&gt;
&lt;option value="02"&gt;02&lt;/option&gt;
&lt;option value="03"&gt;03&lt;/option&gt;
&lt;option value="04"&gt;04&lt;/option&gt;
&lt;option value="05"&gt;05&lt;/option&gt;
&lt;option value="06"&gt;06&lt;/option&gt;
&lt;option value="07"&gt;07&lt;/option&gt;
&lt;option value="08"&gt;08&lt;/option&gt;
&lt;option value="09"&gt;09&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="11"&gt;11&lt;/option&gt;
&lt;option value="12"&gt;12&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td width="33%"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;select name="year2" id="select17" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;
&lt;option value="2010"&gt;end&lt;/option&gt;
&lt;option value="2002"&gt;2002&lt;/option&gt;
&lt;option value="2003"&gt;2003&lt;/option&gt;
&lt;option value="2004"&gt;2004&lt;/option&gt;
&lt;option value="2005"&gt;2005&lt;/option&gt;
&lt;/select&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td colspan="2"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;input name="startdate" type="text" id="startdate" value="00000000000000"&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td colspan="2"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;input name="enddate" type="text" id="enddate3" value="99999999999999"&gt;
&lt;/font&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="left" valign="top" bgcolor="#FFFFFF"&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;
&lt;input name="submit" type="submit" onFocus="dateOne(), dateTwo()" value="Generate" style="color: #000000; font-family: verdana, arial, sans-serif ; font-weight: normal; font-size: 10px; background-color: #ffffff;"&gt;

<font color=blue>

&lt;script&gt;
function dateOne()
{
dayx=document.form1.day.value
monthx=document.form1.month.value
yearx=document.form1.year.value
document.form1.startdate.value=""+yearx+""+monthx+""+dayx+"000000"
}

function dateTwo()
{
dayx2=document.form1.day2.value
monthx2=document.form1.month2.value
yearx2=document.form1.year2.value
document.form1.enddate.value=""+yearx2+""+monthx2+""+dayx2+"000000"
}
&lt;/script&gt;

</font id=blue>


&lt;/font&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;


&lt;/body&gt;
&lt;/html&gt;</font id=red>

Reply to this topic