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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does not show days according to the month chosen

Status
Not open for further replies.

gradinumcp

IS-IT--Management
Apr 6, 2005
85
US
Heres my code that displays a drop-down menu with Month: and Day:. I want that when user chooses January, it displays 31 days in the days drop-down and for april or june 30 days. However it displays only 30 days for all months--any clue whats wrong????

<form method=POST action=Time.asp name=Page1>
<table>
<tr>
Month: <select name=Month>
<option value=''></option>
<option <% if request("Month")=1 then %>selected<% end if %> value='1'>Jaunary</option>
<option <% if request("Month")=2 then %>selected<% end if %> value='2'>February</option>
<option <% if request("Month")=3 then %>selected<% end if %> value='3'>March</option>
<option <% if request("Month")=4 then %>selected<% end if %> value='4'>April</option>
<option <% if request("Month")=5 then %>selected<% end if %> value='5'>May</option>
<option <% if request("Month")=6 then %>selected<% end if %> value='6'>June</option>
<option <% if request("Month")=7 then %>selected<% end if %> value='7'>July</option>
<option <% if request("Month")=8 then %>selected<% end if %> value='8'>August</option>
<option <% if request("Month")=9 then %>selected<% end if %> value='9'>September</option>
<option <% if request("Month")=10 then %>selected<% end if %> value='10'>October</option>
<option <% if request("Month")=11 then %>selected<% end if %> value='11'>November</option>
<option <% if request("Month")=12 then %>selected<% end if %> value='12'>December</option>

</select>&nbsp;&nbsp;

<% if Month(Date())=1 or Month(Date())=3 or Month(Date())=5 or Month(Date())=7 or Month(Date())=8 or Month(Date())=10 or Month(Date())=12 then %>

Day: <select name=Day class=fields>
<option value=''></option>

<%
x=1

do while x<=31 %>

<option <% if cint(request("Day"))=x then %>selected<% end if %> value='<%=x%>'><%=x%></option>
<% x=x+1
Loop %>

<% elseif Month(Date())=4 or Month(Date())=6 or Month(Date())=9 or Month(Date())=11 then %>

Day: <select name=Day class=fields>
<option value=''></option>

<%
x=1

do while x<=30 %>

<option <% if cint(request("Day"))=x then %>selected<% end if %> value='<%=x%>'><%=x%></option>
<% x=x+1

Loop %>
<% else %>

Day: <select name=Day class=fields>
<option value=''></option>

<%
x=1

do while x<=28 %>
<option <% if cint(request("Day"))=x then %>selected<% end if %> value='<%=x%>'><%=x%></option>
<% x=x+1
Loop %>
<% end if %>
</select>&nbsp;&nbsp;

Year: <select name=Year class=fields>
<option value=''></option>
<%
x=0

do while x<>2 %>

<option <% if cint(request("Year"))=Year(Date())-x then %>selected<% end if %> value='<%=Year(Date())-x%>'><%=Year(Date())-x%></option>
<% x=x+1
Loop %>

</select>&nbsp;&nbsp;

<input type=button value="Get Time Information" class=fields2 onclick="CheckVals();">
</td>

</tr>
</table>
</form>
 
i would just do this to get the number of days...

<%
response.write Day(DateSerial(Year(today), month(today),day(today)))
%>


-DNG
 
BTW, what is your CheckVals() function is doing?? are you self referrencing/submitting the form...i dont see the code for that though...

-DNG
 
What's happening is that you're confusing server-side code with client-side code.

All ASP code -- everything inside <% %> tags -- is processed before the user ever gets the page. Every bit of it. And none of it runs once the user -- the client -- gets it. As a result, all of your Ifs are related to the one request value (or no value, the first time the page is drawn).

What you need is some client-side Javascript that changes the values in the second drop-down when the user makes changes in the first one. This is covered in the Javascript forums faqs: faq216-335 and faq216-4766 both explain it.

So you'll just have regular HTML for the month and day (with 31 days in the day dropdown) and then you'll add the Javascript code from one of the faqs to have it change the second based on the first. You won't need ASP for it at all.
 
Hey Genimuse--I you are right--I was thinking about the same thing a while back.

Can you tell me something thats easier than doing the stuff that you mentioned in the links. Something where i can somehow pass the selected month value so the days are automatically displayed accordingly?


DNG--the checkvals script just checks if user has selected a value in each drop-down. If not it throws an Alert.

Also I do not want to get the month from today. I want to be able to choose the month from the drop-down and the days drop-down should change accordingly to show either 28days(for feb)/30days/31days.

Thanks for your feedback guys:)

 
Thanks a bunch DNG--that'll be very helpful:)
 
here is just an example of how you would change the contents of second dropdown depending on what is selected in the first...

Code:
<form name="cascade">
<select name="selList1" size="1" onchange="fillSel(this)"> 
<option selected>-Select Month-</option>
<option value="selList2">January</option>
<option value="selList3">February</option>
<option value="selList4">March</option> 
<option value="selList5">April</option> 
<option value="selList6">May</option> 
<option value="selList7">June</option> 
<option value="selList8">July</option> 
<option value="selList9">August</option> 
<option value="selList10">September</option> 
<option value="selList11">October</option> 
<option value="selList12">November</option> 
<option value="selList13">December</option> 
</select>

<select name="destList" size="1" onchange="doSel(this)">
<option>-- Number of Days -- </option>
</select>
</form> 

<script language="javascript">
<!-- 
selList2 = new Array("31");
selList3 = new Array("28");
selList4 = new Array("31");
selList5 = new Array("30");
selList6 = new Array("31");
selList7 = new Array("30");
selList8 = new Array("31");
selList9 = new Array("31");
selList10 = new Array("30");
selList11 = new Array("31");
selList12 = new Array("30");
selList13 = new Array("31");


function fillSel(selObj)
{
   var i = j = 0;
   var newItem;
   var src;
   var srcName = "";

   for (i = 0; i < selObj.length; i++)
      if (selObj.options[i].selected)
         srcName = selObj.options[i].value;

   src = eval(srcName);

   with (document.cascade.destList) 
   {
      options.length = 0;
      for (i = 0; i < src.length; i++)
      {

         newItem = options.length;
   	     options[newItem] = new Option(src[i]);
         options[newItem].value = src[i+1];
         i++;
      }
      options[0].selected = true;
   }
   if (!isOk)
     history.go(0);
}


function doSel(selObj)
{
  for (i = 1; i < selObj.length; i++)
    if (selObj.options[i].selected)
       location.href = selObj.options[i].value;
}

//--> 
</script>

run it and see it in action...of course you can change the function so that it will list all the days instead of just the number of days...

also look at this link:


if you have any problem adapting it to your requirements then i would suggest you to post your question in javascript forums..i am sure you will get a reply there...

-DNG
 
Thanks DNG for all your effort. However i do not see anything in the drop-down no matter which month i choose. Do i need to populate the list somewhere?
 
what?? did you copy all the code and paste in file called test.asp and run it...

-DNG
 
Ya i did. And what i see i tht you have written the code to display the number of days. I want tht once the user chooses January in the 1st drop-down menu, in the 2nd drop-down i should be able to see 1,2,3---31. Similarly for February, it should show 1,2,3,4---28 and so forth.
 
i know...i was just showing you an example of how to achieve populating the second dropdown based on the selection in the first dropdown...

and i provided you the link which how to write a list of numbers instead of just the number of days...

i just made this sample so that you can understand the concept...

as i said you can always post this question on javascript forums because its more related to javascript...

-DNG
 
Well thanks for all your effort. I saw the code in html and it looks good. I did see the links where i can modify it to display all the days. However when i put it in my asp it dint work alright. Anyways I have posted it in javascript forum also just incase.
 
in the code...if you change this...

selList2 = new Array("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31");

see what happens...

you can build this kind of string use a function that loops according to the month selected..

-DNG
 
Nopes nothing--the moment i change the month, it shows the error:-Object Expected!!
 
Try taking out the following lines:
Code:
if (!isOk)
     history.go(0);

barcode_1.gif
 
thats a copy paste error...please delete those two lines as Tarwn suggested.

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top