Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date doesn't display on month selection

Status
Not open for further replies.

multichild

Programmer
Jan 28, 2006
76
GB
I have a form that contains a variety of functions for a tutorial. I have a problem with one of the functions, in that the date doesnt display straight away without selecting a month first.

Code:
<script language="javascript">
function updateDay() {
// Clear existing values from the Day List
var theDayList = window.document.form1.eventDate;
var optionCounter;
for (optionCounter = theDayList.length - 1; optionCounter >= 0 ; optionCounter --)
  {
  theDayList.options[optionCounter] = null;
  }
// Add values from the appropriate hidden field
var vYear = window.document.form1.eventYear.value;
var vMonth = window.document.form1.eventMonth.value;
var x = 0;
for (x=1; x<32; x++)
  {
  var vDate = vMonth + "/" + x + "/" + vYear;
  var chkDate = new Date(vDate);
  if (chkDate.getMonth()+1 == vMonth)
	{ 
   var option = new Option(x,x);
  theDayList.options[x-1] = option;
	}
  }
}
</script>
<script>

function monthName() {
	MonthName(request.form("eventMonth"))
}
</script>

<tr>
  <td><strong>Day:</td>
  </tr>
<tr>
  <td>
    <select name="eventDay">
    <option>Monday</option>
    <option>Tuesday</option>
    <option>Wednesday</option>
    <option>Thursday</option>
    <option>Friday</option>
    <option>Saturday</option>
    <option>Sunday</option>
  </select>
</td>
  </tr>
<tr>
<tr>
  <td>Month:</td>
  </tr>
<tr>
  <td>
    <select name="eventMonth" onchange="updateDay()">
    <%
	 theMonth = month(now())
	 for x = 1 to 12
		if theMonth = x then 
		  response.write("<option selected value='" & x & "'>" & monthname(x) & "</option>")
		else
		  response.write("<option value='" & x & "'>" & monthname(x) & "</option>")
		end if
	 next
	 %>
  </select>
    </td>
  </tr>

<tr>
  <td>Date:</td>
  </tr>
<tr>
  <td>
    <select name="eventDate"></select>
  </td>
  </tr>
<tr>
  <td><strong>Year:</td>
  </tr>
<tr>
  <td>
    <Select name="eventYear" onchange="updateDay()">
    <% 
   for x = 0 to 9
  theYear = Year(now()) + x
  if theYear = year(now()) then
	response.write("<option selected value='" & theYear & "'>" & theYear & "</option>")
  else
	 response.write("<option value='" & theYear & "'>" & theYear & "</option>")
	end if  
	Next
	%>
  </select>
    </td>
  </tr>

Accend Web Solutions

 

Of course it doesn't - you populate the date by the month field trigger using a javascript function. So it will never have anything until that javascript function is triggered.

A smile is worth a thousand kind words. So smile, it's easy! :)
 

You can either pre-populate the field as you have done with the rest of them, or you can run the javascript function when the page loads - google will provide you with plenty of examples of how to do that, search for "javascript onload"

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top