*****begin
<script language="javascript">
function makeDayList(month){
var now = new Date();
//need the month-1 because january=0 in javascript
var daysInMonth = 32 - new Date(now.getYear(), month-1, 32).getDate();
//main stumbling block
document.monthDay.day.options.length = daysInMonth;
//options also start at 0
for(var i=0 ; i<daysInMonth ; i++){
document.monthDay.day.options[i].value=i+1;
document.monthDay.day.options[i].text=i+1;
}//for
}//function
</script>
<form name="monthDay">
<select name="month"
onChange="javascript:makeDayList(this.options[this.selectedIndex].value);">
<option value="1" SELECTED>January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<!-- put 10~ blank options in the select because netscape4~ does not redraw
page when elements change. -->
<select name="day">
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
</form>
*****end
The trick is to set the length of the day select list to the number of days
in the selected month. Tested in ns6.2 and ns4.78. if you were to not
include the blank options in the day select list, the list would not draw on
ns4~ and you would not be able to select them.
Good luck,
Alexander Sicular
Chief Technology Architect
Neurological Institute of New York
Columbia University
as867 [at] columbia {dot} edu
|-----Original Message-----
|From: Yager, Brian T Contractor/NCCIM
|[mailto:[EMAIL PROTECTED]]
|Sent: Thursday, February 21, 2002 4:39 PM
|To: CF-Talk
|Subject: OT: Any Javascript people out there? I need help with
|select bo xes...
|
|
|sorry about the OT post..I need help with a select box. I am
|making 2 select boxes (Month and Day). when the user changes
|the month, I want the javascript to delete what is in the day
|select box and fill it with the number of days in that month.
|I have the deleting part working. It just won't add. I'm not
|sure what I need to do. Here is my code(Please ignore that I
|HAVE to use ASP for this)..
|
|
|<select name="month" size="1"
|onChange="changeMonth(this.form,this.form.day,this.form.month.o
|ptions[this.form.
|month.selectedIndex].value);">
| <option value="1" SELECTED>January</option>
| <option value="2">February</option>
| <option value="3">March</option>
| <option value="4">April</option>
| <option value="5">May</option>
| <option value="6">June</option>
| <option value="7">July</option>
| <option value="8">August</option>
| <option value="9">September</option>
| <option value="10">October</option>
| <option value="11">November</option>
| <option value="12">December</option>
| </select></td>
| <td>Day:</td><td><select name="day" size="1">
| <%for i = 1 to 31%>
| <option value="<%=i%>"><%=i%></option>
| <%next%></select></td>
|
|
|
|<script language="JavaScript1.2">
|
|
|function changeMonth(theform,selectCtrl,iValue) {
|var oNewOption;
|iSelection = iValue;
|
|iOptLen=selectCtrl.length + 1;
|
|for (i=0;i<=iOptLen;i=i+1) {
|
| selectCtrl.options[0] = null;
|
|
| }
|
|if (iSelection == "1" || iSelection == "3" || iSelection ==
|"5" || iSelection == "7" || iSelection == "8" || iSelection ==
|"10" || iSelection == "12") {
| for (i=0;i<=30;i=i+1) {
| selectCtrl.options[i] = i+1;
| }
|
|}
|if (iSelection == "2") {
| for (i=0;i<=27;i=i+1) {
| selectCtrl.options[i] = i+1;
| }
|}
|if (iSelection == "4" || iSelection == "6" || iSelection ==
|"9" || iSelection ==
|"11") {
| for (i=0;i<=29;i=i+1) {
| selectCtrl.options[i] = i+1;
| }
|
|}
|
|
|
|}
|
|
|
|</script>
|
|
|
| Someone please drop me a line and tell me what I am doing
|wrong. I am absolutely clueless....
|
|
|
|Thanks,
|
|
|Brian Yager
|President - North AL Cold Fusion Users Group
|Sr. Systems Analyst
|NCCIM/CIC
|[EMAIL PROTECTED]
|(256) 842-8342
|
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
Instant Activation � $99/Month � Free Setup
http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists