Forums

ASP

This topic is locked

Selecting current hour in dropdown list

Posted 23 Jan 2006 12:07:05
1
has voted
23 Jan 2006 12:07:05 Tom Theys posted:
Hi,

I'm currently working on an ASP wabsite where the user is able to adjust date and time of a post with a dropdown list.
Everyhting works, but I have some problems with the hour.
For day, month and year I use this code, works perfect:

<font color=blue>
&lt;select name="u_day" class="form_field"&gt;
&lt;% for counter = 1 to 31 %&gt;
&lt;option &lt;%
if counter = day(rsPosts.Fields.Item("PostDate".value) then %&gt;
selected
&lt;% end if %&gt;
value="&lt;%= counter %&gt;"&gt;
&lt;%= counter %&gt;&lt;/option&gt;
&lt;% next %&gt;
&lt;/select&gt;

&lt;select size="1" name="u_month" class="form_field"&gt;
&lt;% for counter = 1 to 12 %&gt;
&lt;option &lt;%
if counter = month(rsPosts.Fields.Item("PostDate".value) then %&gt; selected &lt;% end if %&gt; value="&lt;%= counter %&gt;"&gt;&lt;%= MonthName(counter) %&gt;&lt;/option&gt;
&lt;% next %&gt;
&lt;/select&gt;

&lt;select size="1" name="u_year" class="form_field"&gt;
&lt;% for counter = 2005 to 2010 %&gt;
&lt;option &lt;%
if counter =year(rsPosts.Fields.Item("PostDate".value) then %&gt; selected &lt;%
end if %&gt; value="&lt;%= counter %&gt;"&gt;&lt;%= counter %&gt;&lt;/option&gt;
&lt;% next %&gt;
&lt;/select&gt;
</font id=blue>

Now for the hour I'm using this, but sometimes it does not work, so this isn't the way to do it.

<font color=blue>
&lt;select name="u_time" class="form_field"&gt;
&lt;% for counter = 8 to 22 %&gt;
&lt;option &lt;%
if counter = hour(rsPosts.Fields.Item("PostDate".value) then %&gt; selected &lt;% end if %&gt; value="&lt;%= counter %&gt;:00:00"&gt;&lt;%= counter %&gt;:00:00&lt;/option&gt;
&lt;% next %&gt;
&lt;/select&gt;
</font id=blue>

does anyone knows how to work with the hours?
thanks!

Replies

Replied 25 Jan 2006 16:13:28
25 Jan 2006 16:13:28 Tom Theys replied:
I'm also using a javascript function to get the dates from the fields

&lt;form ACTION="&lt;%=MM_editAction%&gt;" METHOD="POST" name="form1" onSubmit="GetDate()"&gt;

the javascript GetDate():

&lt;script language="JavaScript"&gt;
&lt;!--
function GetDate() {
document.form1.PostDate.value = document.form1.u_day.value + '/' + document.form1.u_month.value + '/' + document.form1.u_year.value + ' ' + document.form1.u_time.value;
}
//--&gt;
&lt;/script&gt;

maybe I'm doing something wrong here

and the variables
&lt;%
u_date=request.form("u_date"
u_month=request.form("u_month"
u_day=request.form("u_day"
u_year=request.form("u_year"
u_time=request.form("u_time"
%&gt;

If I choose 'edit post' the hour comes correct in the dropdown list, but when I choose update, even when I leave the current hour selected, it removes the hour in the DB date field, only the date get's updated and the time is deleted.


Edited by - tothprod on 25 Jan 2006 16:14:51
Replied 26 Jan 2006 11:47:41
26 Jan 2006 11:47:41 Tom Theys replied:
Ok, found it!
I had a code in my update function that converted the date to an ISO date, only the day, month and year was converted, silly me <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Reply to this topic