Form Doesn't Work Properly

Discussion in 'ASP General' started by Mike, Dec 21, 2003.

  1. Mike

    Mike Guest

    Hi,

    I'm new to ASP and can't get this form to work. It's a simple page
    that draws a calendar for the current month and then you can select a
    new month and it draws the new calendar. It works fine the first time
    I load the page but doesn't work when I submit the form. It doesn't
    seem to be properly evaluating the first if statement for drawing the
    calendar but all the variables seem to be correct (i.e. it it using
    the values passed from the form). Any suggestions? It's running on
    Windows 2000. The code is below. Thanks in advance.

    Mike


    <%@ Language=VBScript %>
    <% Option Explicit %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

    <head>
    <title>Calendar</title>
    </head>

    <body topmargin="0" leftmargin="0" bgcolor="#FFFFFF" text="#000000"
    marginwidth="0" marginheight="0">

    <%

    'declare variables


    Dim currentYear, firstDay, currentDate, currentMonth, i, y, start,
    finish

    if (Request.form("themonth")) then
    currentMonth = Request.form("themonth")
    else
    currentMonth = Month(Date)
    end if
    if (Request.form("theyear")) then
    currentYear = Request.form("theyear")
    else
    currentYear = Year(Date)
    end if

    currentDate = DateSerial(currentYear, currentMonth, 1)
    firstDay = Weekday(currentDate)


    %>

    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <form action="calendar.asp" method="POST">
    <tr>
    <td colspan="7" align="center">
    <select name="themonth">
    <option value="1" <% if (currentMonth = 1) then Response.write "
    selected" %>>January</option>
    <option value="2" <% if (currentMonth = 2) then Response.write "
    selected" %>>February</option>
    <option value="3" <% if (currentMonth = 3) then Response.write "
    selected" %>>March</option>
    <option value="4" <% if (currentMonth = 4) then Response.write "
    selected" %>>April</option>
    <option value="5" <% if (currentMonth = 5) then Response.write "
    selected" %>>May</option>
    <option value="6" <% if (currentMonth = 6) then Response.write "
    selected" %>>June</option>
    <option value="7" <% if (currentMonth = 7) then Response.write "
    selected" %>>July</option>
    <option value="8" <% if (currentMonth = 8) then Response.write "
    selected" %>>August</option>
    <option value="9" <% if (currentMonth = 9) then Response.write "
    selected" %>>September</option>
    <option value="10" <% if (currentMonth = 10) then Response.write "
    selected" %>>October</option>
    <option value="11" <% if (currentMonth = 11) then Response.write "
    selected" %>>November</option>
    <option value="12" <% if (currentMonth = 12) then Response.write "
    selected" %>>December</option>
    </select>
    <select name="theyear">
    <%
    start = currentYear - 1
    finish = currentYear + 3
    for y=start to finish
    Response.write "<option value=""" & y & """"
    if (y = currentYear) then Response.write " selected"
    Response.write ">" & y & "</option>"
    next
    %>
    </select>
    <input type="submit" name="submit" value="Go">
    </td>
    </tr>
    </form>
    <tr>
    <td>Sunday</td>
    <td>Monday</td>
    <td>Tuesday</td>
    <td>Wedenesday</td>
    <td>Thursday</td>
    <td>Friday</td>
    <td>Saturday</td>
    </tr>
    <tr>
    <%

    'draw calendar

    For i=1 to 42
    Response.Write "<td>"
    if(Month(currentDate)<>currentMonth) or (i < firstDay) then
    Response.write "&nbsp;"
    else
    Response.write Day(currentDate)
    end if
    Response.write "</td>"
    if (i mod 7)="0" Then
    Response.write "</tr>"
    end if
    if (i >= firstDay) Then
    currentDate=dateAdd("d", 1, currentDate)
    end if
    Next

    %>

    </table>
    </body>
    </html>
     
    Mike, Dec 21, 2003
    #1
    1. Advertising

  2. Mike

    Evertjan. Guest

    Mike wrote on 21 dec 2003 in microsoft.public.inetserver.asp.general:
    > if (Request.form("themonth")) then


    A request.form ALWAYS exist, if not entered it is an empty string.

    So:

    if Request.form("themonth") <> "" then

    The parentheses are not needed and just add execution overhead.

    In fact this is enough:

    if Request.form("themonth") > "" then

    because no string can be smaller, in (V)basic terms, than an empty string.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    2
    Views:
    2,261
    John Saunders
    Jun 4, 2004
  2. Replies:
    3
    Views:
    1,634
    S. Justin Gengo
    Dec 27, 2005
  3. Jeff Robichaud
    Replies:
    0
    Views:
    381
    Jeff Robichaud
    Mar 7, 2006
  4. John Salerno
    Replies:
    3
    Views:
    610
    John Salerno
    Feb 2, 2006
  5. balasubramaniam
    Replies:
    2
    Views:
    439
    Andrey Tarasevich
    Nov 30, 2003
Loading...

Share This Page