Current location: Hot Scripts Forums » Programming Languages » ASP » Selecting current hour in dropdown list


Selecting current hour in dropdown list

Reply
  #1 (permalink)  
Old 01-23-06, 04:40 AM
toth toth is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Selecting current hour in dropdown list

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:

Code:
<select name="u_day" class="form_field">
<% for counter = 1 to 31  %>
<option <%
if counter = day(rsPosts.Fields.Item("PostDate").value) then %>
selected
<% end if %>
value="<%= counter %>">
<%= counter %></option>
<% next %>
</select>

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

<select size="1" name="u_year" class="form_field">
<% for counter = 2005 to 2010 %> 
<option <%
if counter =year(rsPosts.Fields.Item("PostDate").value) then %> selected <%
end if %> value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
Now for the hour I'm using this, but sometimes it does not work, so this isn't the way to do it.

Code:
<select name="u_time" class="form_field">
<% for counter = 8 to 22 %>
<option <%
if counter = hour(rsPosts.Fields.Item("PostDate").value) then %> selected <% end if %> value="<%= counter %>:00:00"><%= counter %>:00:00</option>
<% next %>
</select>
does anyone knows how to work with the hours?
thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-23-06, 05:53 PM
koncept
Guest
 
Posts: n/a
why not use military time or 1-12 with am/pm?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-24-06, 04:51 AM
toth toth is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
I only need the am. If the user create's a new post they have this options to choose from
Code:
<select name="u_time" class="form_field">

<option value="08:00:00">08:00</option>
<option value="09:00:00">09:00</option>
<option value="10:00:00">10:00</option>
<option value="11:00:00">11:00</option>
<option value="12:00:00">12:00</option>
<option value="13:00:00">13:00</option>
<option value="14:00:00">14:00</option>
<option value="15:00:00">15:00</option>
<option value="16:00:00">16:00</option>
<option value="17:00:00">17:00</option>
<option value="18:00:00">18:00</option>
<option value="19:00:00">19:00</option>
<option value="20:00:00">20:00</option>
<option value="21:00:00">21:00</option>
<option value="22:00:00">22:00</option>

</select>
The problem is on the edit page. I need to be sure that he only take's the hours
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-24-06, 07:24 AM
koncept
Guest
 
Posts: n/a
make it simpler, why not update the time based upon when it was entered/updated. it sounds like your trying to build a forum. most forus do not allow users to pick thier post time. time zone yes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-25-06, 09:17 AM
toth toth is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
It's no forum, it's more like a blog. The administrator has the option to choose when the post is displayed. This way the admin can make posts for the upcoming week. So he's got the option to choose which date en which hour the post needs to be displayed. The blog only show's the post from the current date. When the admin sets the day or hour to one in the future it automaticly comes in the concepts. The post will then be displayed when the date and time is now.

I'm also using a javascript function to get the dates from the fields

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1" onSubmit="GetDate()">

the javascript GetDate():

<script language="JavaScript">
<!--
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;
}
//-->
</script>

maybe I'm doing something wrong here

and the variables
<%
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")
%>

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 01-25-06, 05:51 PM
koncept
Guest
 
Posts: n/a
check that the drop down is nammed the same as the form item you are requesting
enable option explicit
check htat the db column is named correctly and it is inculded in the update statement
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 01-26-06, 04:16 AM
toth toth is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
All form and fields are correct, it's the same as when I post a new post, and that works fine. I pass the value from the four fields to a hidden field with the GetDate() function. The name of the DB field is PostDate

the NEW POST code:

Code:
<% 
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")
%>

<script language="JavaScript">
<!--
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;
} 
//-->
</script>

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1" onSubmit="GetDate()">

<select name="u_day" class="form_field">
<% for counter = 1 to 31  %>
<option <% if counter = day(date()) then %> selected <% end if %>
value="<%= counter %>">
<%= counter %></option>
<% Next %>
</select>

<select size="1" name="u_month" class="form_field">
<% for counter = 1 to 12 %> 
<option <% if counter = month(date()) then %> selected <% end if %> value="<%= counter %>"><%= MonthName(counter) %></option>
<% next %>
</select> 

<select size="1" name="u_year" class="form_field">
<% for counter = 2005 to 2010 %> 
<option
<% if counter =year(date()) then %> selected <% end if %>
value="<%= counter %>"><%= counter %></option>
<% next %>
</select>

<select name="u_time" class="form_field">
<option value="08:00:00">08:00</option>
<option value="09:00:00">09:00</option>
<option value="10:00:00">10:00</option>
<option value="11:00:00">11:00</option>
<option value="12:00:00">12:00</option>
<option value="13:00:00">13:00</option>
<option value="14:00:00">14:00</option>
<option value="15:00:00">15:00</option>
<option value="16:00:00">16:00</option>
<option value="17:00:00">17:00</option>
<option value="18:00:00">18:00</option>
<option value="19:00:00">19:00</option>
<option value="20:00:00">20:00</option>
<option value="21:00:00">21:00</option>
<option value="22:00:00">22:00</option>
</select> 

<input name="PostDate" type="hidden" id="PostDate">

</form>
the EDIT POST code

Code:
<% 
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")
%>

<script language="JavaScript">
<!--
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;
} 
//-->
</script>

<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1" onSubmit="GetDate()">

<select name="u_day" class="form_field">
<% for counter = 1 to 31  %>
<option <% if counter = day(rsPosts.Fields.Item("PostDate").value) then %> selected <% end if %>
value="<%= counter %>"><%= counter %></option>
<%Next%>
</select>

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

<select size="1" name="u_year" class="form_field">
<% for counter = 2005 to 2010 %> 
<option <% if counter =year(rsPosts.Fields.Item("PostDate").value) then %> selected <% end if %>
value="<%= counter %>"><%= counter %></option>
<% next %>
</select>
						
<select name="u_time" size="1" class="form_field">
<% for counter = 8 to 22 %>
<option <% if counter = Hour(rsPosts.Fields.Item("PostDate").value) then %> selected <% end if %>
value="<%= counter %>:00:00"><%= counter %>:00</option>
<% next %>
</select> 

<input name="PostDate" type="hidden" id="PostDate">

</form>
the new post works fine, only the edit doesn't update the time. It deletes it from the DB field. Verry strange. It seems to not reconize the <%counter%> or something. Strange that the day, month and year has no problems.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 01-26-06, 04:24 AM
toth toth is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, FOUND IT!!!
I was converting the ISO date in the update function, only day/month/year was converted to the ISO date

Thanks for the help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown list Last value aish ASP.NET 3 01-06-06 05:23 PM
php dropdown list validation eddo32 PHP 1 12-07-05 10:24 AM
Dropdown to list current year, and 74 years back APuppyDog JavaScript 1 10-01-04 10:59 PM
Can I populate a dropdown list???? zorrox02 JavaScript 4 10-01-04 05:03 AM


All times are GMT -5. The time now is 09:00 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.