Click to See Complete Forum and Search --> : Populate a dropdown box with 2 dates


rosenzl
03-04-2003, 02:53 PM
I am trying to populate a dropdown box with 2 date variables called todaydate and tomdate. First it will show "-choose-", followed by todays's date and then tomorrow's date.

The selected date needs to be validated by my hidden function called Validate. This I can do, but I can't figure out the syntax for the dates. Following is another dropdown box which you can make the changes to so I can see the proper syntax.

__________________________________________________
__
<!--webbot bot="Validation" s-display-name="Choose" b-disallow-first-item="TRUE" --><Select Name="pudeliv">
<option name="--choose--" value="-choose-" <% if pudeliv = "-choose-" then response.write "selected" end if%>>-choose-</option>
<option name=Pickup" value="Pickup" <% if pudeliv = "pickup" then response.write "selected" end if %>>Pickup</option>
<option name="Delivery" value="Delivery" <% if pudeliv = "Delivery" then response.write "selected" end if %>>Delivery</option>
</select>
__________________________________________________
__



Thanks for your help.

Larry

rosenzl
03-05-2003, 07:02 AM
Dave, see www.emailfoodorder.com/emailemoform.asp

I want to put the 2 dates I created:

<%
dim todaydate
dim tomdate
todaydate = date
tomdate = (todaydate + 1)
%>

in the original code I sent you. I want today's date (todaydate) and tomorrow's date (tomdate) in that code.

Larry

rosenzl
03-05-2003, 08:45 AM
Dave, thanks. However, the dates are currently in the format of mm/dd/yyyy. I just want to make their values show in the dropdown box. Also, where you test for pickup and delivery, I need the todaydate and tomdate. I just used the pudeliv as an example of the format for another dropdown box.

Effectively, I want the dropdown to look like this:

-choose-
3/5/2003
3/6/2003

Thanks,

Larry

rosenzl
03-05-2003, 09:34 PM
Dave, I have no idea what you are talking about. Did I change what around? No, it's not working.

What you gave me still will show Pickup or Delivery in the dropdown box. Also, because I need to use variable names in the if statements, I can't figure that out without getting syntax errors. It's like I need a couple of sets of <% %>, but no matter how I code it, it doesn't work.

Ribeyed
03-06-2003, 02:57 PM
hi,
ok not sure which format you are wanting your dates to be. You have 3/5/2003 now is that the 3rd of May 2003 or 5th of March 2003?
Also not sure if you are wanting English US dates or English UK dates.
Uk Dates are dd/mm/yyyy
US dates are m/d/yyyy

Saying all that here is code to convert your date to the English US format.


<%
ReturnDateTime 1033, "English (US)"
Sub ReturnDateTime(locale, description)
Session.LCID = locale
End Sub
dim todaydate
dim tomdate
todaydate = formatdatetime(DATE())
tomdate = dateadd("d", 1, todaydate)
val = request.form("val")
if val = "yes" then
selecteditem = request.form("thedates")
end if
%>
<form name="form1" method="post" action="/dateselect.asp">
<Select Name="thedates">
<option name="-choose-" value="-choose-" <% if thedates = "-choose-" then response.write "selected" end if%>>-choose-</option>
<option name="Pickup" value="<%=todaydate%>" <% if thedates = " & todaydate &" then response.write "selected" end if %>><%= todaydate %></option>
<option name="Delivery" value="<%=tomdate%> " <% if thedates = " & tomdate &" then response.write "selected" end if %>><%= tomdate %></option>
</Select>
<input type="submit" name="Submit" value="Submit">
<input name="val" type="hidden" id="val" value="yes">
</form>
<%=selecteditem%>

Hope this helps.

Ribeyed
03-07-2003, 05:31 AM
1. the <%selecteditem%> after the </form> is being displayed at the bottom of form after the submit.

this was just to make sure the value was being passed from the form. I just write the value out to screeen you don't need this line.


2. on the form you have action="/dateselect.asp". I assume you mean the acion I already have.(emaildemoform.asp).

you post back to the same page. This should be the same name as your page.

3. is the following what should set focus to the date in the dropdown box? Should it be in the body or in the head? Could it be part of the Validate function?


Val = request.form("val")
if val="yes" Then
selecteditem = request.form("thedates")
End if


well sort of. if its the first time the page is displayed then you don't need to validate anything. If the form has been submitted then the Val will be yes and the select box value is requested and set to selectedItem. Now in your select box you are saying if selected item is equal to the option value then this is the one selected to write selected.

rosenzl
03-07-2003, 06:08 AM
OK, so why is the dropdown box going back to "-Choose-" after the submit?

Here are my selects:
<!--webbot bot="Validation" s-display-name="Choose" b-disallow-first-item="TRUE" --><Select Name="thedates">
<option name="-choose-" value="-choose-" <% if thedates = "-choose-" then response.write "selected" end if%>>-choose-</option>
<option name="Pickup" value="<%=todaydate%>" <% if thedates = " & todaydate &" then response.write "selected" end if %>><%= todaydate %></option>
<option name="Delivery" value="<%=tomdate%>" <% if thedates = " & tomdate &" then response.write "selected" end if %>><%= tomdate %></option>

</Select>

Her is my test:
Val = request.form("val")
if val = "yes" Then
selecteditem = request.form("thedates")
End if

rosenzl
03-07-2003, 06:29 AM
Could this be the problem? In the body, I have this code:

<%
dim todaydate
dim tomdate
todaydate = formatdatetime(DATE())
tomdate = dateadd("d", 1, todaydate)
%>

I am getting the dates every time on the page. Should I be doing this just once, before the submit?

If val <> "yes" then
todaydate = formatdatetime(DATE())
tomdate = dateadd("d", 1, todaydate)
end if

I just tried this, but still back to -choose- after the submit.

Ribeyed
03-07-2003, 01:34 PM
hi,
create yourself a new page and copy and paste the code i posted, run this you will see it works. Can you post all your code for the page plz and then i will be able to pin point where the code is not working?