Click to See Complete Forum and Search --> : Multiple date selects one form


MickeyFinn
11-10-2003, 06:15 PM
Hi there,

Firstly I need to say that Im very inexperienced in Javascript!
I need a dynamic date picker that I use multiple times in a form but it still performs the task of changing the dates depending on the month selected (like only 28 days for Feb unless its a leap year then 29 etc).

I got this function which works fine for one instance in a form.

Javascript:

function populate(objForm,selectIndex) {
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++) {
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++) {
objForm.day.options[i] = new Option(i+1);
}

}


HTML:

<select name=year onChange="populate(this.form,this.form.month>.selectedIndex);">
<option selected value=2003>2003</option>

</select>

<select name=month onChange="populate(this.form,this.selectedIndex);">
<option value=00 selected>Select Month</option>
<option value=01>January</option>
<option value=02>February</option>
<option value=03>March</option>
<option value=04>April</option>
<option value=05>May</option>
<option value=06>June</option>
<option value=07>July</option>
<option value=08>August</option>
<option value=09>September</option>
<option value=10>October</option>
<option value=11>November</option>
<option value=12>December</option>
</select>

<select name=day>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
</select>


However I want to use it in an ASP function like this:

Function GetDateTest()
%>
<form name="DatePicker" action="Action.asp">
<%
call DatePick("year","month","day")
%>
<input name="Submit" type="submit" class="searchForm" value="search">
</form>
</center>
<%
end function


function DatePick(gvstryear, gvstrmonth, gvstrday)
%>
<table border=0>
<tr>
<td align=center>
<select name=<%=gvstryear%> onChange="populate(this.form,this.form.<%=gvstrmonth%>.selectedIndex);">
<option selected value=2003>2003</option>

</select>

<select name=<%=gvstrmonth%> onChange="populate(this.form,this.selectedIndex);">
<option value=00 selected>Select Month</option>
<option value=01>January</option>
<option value=02>February</option>
<option value=03>March</option>
<option value=04>April</option>
<option value=05>May</option>
<option value=06>June</option>
<option value=07>July</option>
<option value=08>August</option>
<option value=09>September</option>
<option value=10>October</option>
<option value=11>November</option>
<option value=12>December</option>
</select>

<select name=<%=gvstrday%>>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
</select>
</td>
</tr>
</table>


<%
end function

At the moment this works but i cant figure out how to use it twice in a form like this :

Function GetDate4RbyDest()
%>
<form name="DatePicker" action="Action.asp">
<%
call DatePick("year","month","day")
call DatePick("year1","month1","day1")
%>
<input name="Submit" type="submit" class="searchForm" value="search">
</form>
</center>
<%
end function

Obviously because year1 etc wont work properly in the function but I dont know how to pass in dynamic strings into the javascript function.

Im happy to use another system to do this but this is what Ive started with which is why Ive based the question on it. But I do definately want it to be drop down selects rrather than calandar pop ups as they have to much mouse clicking involved.

Hope that makes sense :) Any help would be greatly appreciated.

Fracture

Khalid Ali
11-11-2003, 06:22 AM
there are tonne of freely available date picker javascript apps out there...just do a google search.