ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 25th, 2003, 10:49 AM
thebloodletting thebloodletting is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 thebloodletting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Need Help With HTML Encode and Select Form Fields Please

G'day All,

I have downloaded and installed an ASP Calendar offered for free by Manohar Kamath from his website. I've modified it to accept two new fields (sStart_Time & sEnd_Time). I want to be able to have drop down selections for the time entry, but do not know how to accomplish this. Please take a look and tell me if this can be done using the <% =Server.HTMLEncode(sStart_Time) %>"> value for this piece or if there is some other way to accomplish this, please let me know.
If I leave it as the following, it works OK, but I want to make it easier for people who are adding to the database:

THIS ONE WORKS JUST FINE:

<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>Start Time</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2><INPUT TYPE=TEXT SIZE=12 MAXLENGTH=12 NAME="START_TIME" VALUE="<% =Server.HTMLEncode(sStart_Time) %>"></FONT><% =imgStart_Time %></TD>
</TR>

----------------------------------------------------------
THIS ONE DOES NOT WORK:

<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>Start Time</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2>
<select name="sStart_Time" VALUE="<% =Server.HTMLEncode(sStart_Time) %>">
<option value=''> Select a Start Time</option>
<option value='1 am'>1 am</option>
<option value='2 am'>2 am</option>
<option value='3 am'>3 am</option>
<option value='4 am'>4 am</option>
<option value='5 am'>5 am</option>
<option value='6 am'>6 am</option>
<option value='7 am'>7 am</option>
<option value='8 am'>8 am</option>
<option value='9 am'>9 am</option>
<option value="10 am">10 am</option>
<option value="11 am">11 am</option>
<option value="12 noon">12 noon</option>
<option value="1 pm">1 pm</option>
<option value="2 pm">2 pm</option>
<option value="3 pm">3 pm</option>
<option value="4 pm">4 pm</option>
<option value="5 pm">5 pm</option>
<option value="6 pm">6 pm</option>
<option value="7 pm">7 pm</option>
<option value="8 pm">8 pm</option>
<option value="9 pm">9 pm</option>
<option value="10 pm">10 pm</option>
<option value="11 pm">11 pm</option>
<option value="12 midnight">12 midnight</option>
</select>
</FONT><% =imgStart_Date %>


Any help would be greatly apreciated. If you need the complete code, please let me know.

Reply With Quote
  #2  
Old August 25th, 2003, 10:55 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
When you say:
-->THIS ONE DOES NOT WORK<--

What do you mean by that? Do you get an error message? what?

Also, make a VIEW/SOURCE of you page, is it the HTML result you were looking for???

Where do you declare sStart_Time ? and what's in it?

Why did you add a VALUE attribute to your <select>...</select>?

Do a VIEW/SOURCE you'll see what it gives you!

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #3  
Old August 25th, 2003, 11:08 AM
thebloodletting thebloodletting is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 thebloodletting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Vince,

I wanted to refrain from posting the complete code because it's alot to wade through, but I'll go ahead. When I say it doesn't work, I mean that it will not update the database. It shows the fields correctly on the page. After I've entered the data and click on "Add", the form resets with the data still there except for the time. The Calendar Batabase does not update. When I leave it as just a Text Field with HTML Encode, it updates the database just fine. Here is the complete code:

<% Option Explicit %>
<!-- #include file = "secure.asp" -->
<!-- #include file = "dsn.asp" -->
<!-- #include file = "adovbs.inc" -->
<%
Dim sStart_Date, sEnd_Date, sEvent_Title, sEvent_Details,sStart_Time, sEnd_Time
Dim imgStart_Date, imgEnd_Date, imgEvent_Title, imgEvent_Details, imgStart_Time, imgEnd_Time
Dim sMode, bError, sScriptPath

' Get the name of the file
sScriptPath = Request.ServerVariables("SCRIPT_NAME")

' Determine if the action required is an add or an edit. If it is an edit,
' retrieve the record and present it to the user. If not, present a
' blank form
If IsEmpty(Request.Form("EVENT")) Then
If NOT IsEmpty(Request.QueryString("Event_ID")) Then
sMode = "EDIT"
Get_Event(Request.QueryString("Event_ID"))
Else
sMode = "ADD"
End If

Show_Form()
Else
Update_Event(Request.Form("EVENT"))
End If
%>
<%
' This routine retrieves the event by the Event_ID. If the event is not found,
' set the mode to an "ADD".
Sub Get_Event(lEvent_ID)
Dim sSQL, Rs
' Create a recordset and open the given event. If the Record is not found
' set the mode to ADD
sSQL = "SELECT * FROM tEvents WHERE Event_ID=" & lEvent_ID
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.MaxRecords = 1
Rs.Open sSQL, sDSN, adOpenStatic, adLockReadOnly, adCmdText

If Not Rs.EOF Then
sStart_Date = Rs("Start_Date")
sStart_Time = Rs("Start_Time")
sEnd_Date = Rs("End_Date")
sEnd_Time = Rs("End_Time")
sEvent_Title = Rs("Event_Title")
sEvent_Details = Rs("Event_Details")
Else
sMode = "ADD"
End If
End Sub
%>

<%
' This routines presents the form to the user. Depending on the mode, the
' form fields are filled with data or blank.
Sub Show_Form()
Dim sButtonMsg, sTitle
If sMode = "ADD" Then
sButtonMsg = "Add Event"
Else
sButtonMsg = "Update Event"
End If
' Set the title of the page depending on if an error occurred during
' form submission or not
If bError = True Then
sTitle = "Error in form submission"
Else
sTitle = "Add/Update an Event"
End If
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Manohar Kamath">
<TITLE><% =sTitle %></TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF onLoad="document.eventfrm.START_DATE.focus()">
<P>&nbsp;</P>
<P ALIGN=LEFT><IMG SRC="images/add_event.gif" WIDTH=200 HEIGHT=20 BORDER=0 ALT="">
</P>
<FORM NAME="eventfrm" ACTION="<% =sScriptPath %>" METHOD=POST>

<TABLE CELLSPACING=5 CELLPADDING=3 BORDER=0 WIDTH=95%>
<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>Start Date</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2><INPUT TYPE=TEXT SIZE=12 MAXLENGTH=12 NAME="START_DATE" VALUE="<% =Server.HTMLEncode(sStart_Date) %>"></FONT><% =imgStart_Date %></TD>
</TR>
<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>Start Time</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2>
<select name="sStart_Time" VALUE="<% =Server.HTMLEncode(sStart_Time) %>">
<option value=''> Select a Start Time</option>
<option value='1 am'>1 am</option>
<option value='2 am'>2 am</option>
<option value='3 am'>3 am</option>
<option value='4 am'>4 am</option>
<option value='5 am'>5 am</option>
<option value='6 am'>6 am</option>
<option value='7 am'>7 am</option>
<option value='8 am'>8 am</option>
<option value='9 am'>9 am</option>
<option value="10 am">10 am</option>
<option value="11 am">11 am</option>
<option value="12 noon">12 noon</option>
<option value="1 pm">1 pm</option>
<option value="2 pm">2 pm</option>
<option value="3 pm">3 pm</option>
<option value="4 pm">4 pm</option>
<option value="5 pm">5 pm</option>
<option value="6 pm">6 pm</option>
<option value="7 pm">7 pm</option>
<option value="8 pm">8 pm</option>
<option value="9 pm">9 pm</option>
<option value="10 pm">10 pm</option>
<option value="11 pm">11 pm</option>
<option value="12 midnight">12 midnight</option>
</select>
</FONT><% =imgStart_Date %></TD>
</TR>
<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>End Date</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Optional</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2><INPUT TYPE=TEXT SIZE=12 MAXLENGTH=12 NAME="END_DATE" VALUE="<% =Server.HTMLEncode(sEnd_Date) %>"></FONT><% =imgEnd_Date %></TD>
</TR>

<TR>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=30%><FONT FACE=Verdana SIZE=2><B>End Time</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2><INPUT TYPE=TEXT SIZE=8 MAXLENGTH=8 NAME="END_TIME" VALUE="<% =Server.HTMLEncode(sEnd_Time) %>"></FONT><% =imgEnd_Time %></TD>
</TR>

<TR>
<TD VALIGN=TOP ALIGN=LEFT><FONT FACE=Verdana SIZE=2><B>Event Title</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT><FONT FACE=Verdana SIZE=2><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=100 NAME="EVENT_TITLE" VALUE="<% =Server.HTMLEncode(sEvent_Title) %>"><% =imgEvent_Title %></FONT></TD>
</TR>

<TR>
<TD VALIGN=TOP ALIGN=LEFT><FONT FACE=Verdana SIZE=2><B>Event Details</B>
<BR><FONT SIZE=1 COLOR='RED'><I>Required</I></FONT></FONT></TD>
<TD VALIGN=TOP ALIGN=LEFT><FONT FACE=Verdana SIZE=2><TEXTAREA COLS=30 ROWS=5 NAME="EVENT_DETAILS" WRAP=PHYSICAL><% =Server.HTMLEncode(sEvent_Details) %></TEXTAREA></FONT><% =imgEvent_Details %></TD>
</TR>

</TABLE>
<BR>
<INPUT TYPE=HIDDEN NAME=EVENT VALUE=<% =sMode %>>
<INPUT TYPE=HIDDEN NAME=EVENT_ID VALUE=<% =Request.QueryString("EVENT_ID") %>>
<FONT FACE="Verdana" SIZE="2"><INPUT TYPE=SUBMIT VALUE="<% =sButtonMsg %>"></FONT>

</FORM>
</BODY>
</HTML>
<% End Sub %>
<%
Sub Update_Event(sUpdateMode)
Dim sErrImage, Rs, sSQL, sTitle
bError = False
sErrImage = "<IMG SRC='images/error.gif' BORDER=0 HEIGHT=15 WIDTH=50>"

' Get the form data into variables
sStart_Date = Request.Form("START_DATE")
sStart_Time = Request.Form("START_TIME")
sEnd_Date = Request.Form("END_DATE")
sEnd_Time = Request.Form("END_TIME")
sEvent_Title = Request.Form("EVENT_TITLE")
sEvent_Details = Request.Form("EVENT_DETAILS")
' The error checking routines start here. If any of the fields fails
' error check, the bError flag is raised, and the corresponding image
' string is set to the image source
' Check to see if Start date is a valid date
If NOT IsDate(sStart_Date) Then
bError = True
imgStart_Date = sErrImage
End If
If Trim(sStart_Time) = "" Then
bError = True
imgEvent_Title = sErrImage
End If

' Check if the End date is a valid date provided it is not empty
If Trim(sEnd_Date) <> "" AND NOT IsDate(sEnd_Date) Then
bError = True
imgEnd_Date = sErrImage
End If
If Trim(sEnd_Time) = "" Then
bError = True
imgEvent_Title = sErrImage
End If

' Check if the event title field is blank
If Trim(sEvent_Title) = "" Then
bError = True
imgEvent_Title = sErrImage
End If

' Check if the event details field is blank
If Trim(sEvent_Details) = "" Then
bError = True
imgEvent_Details = sErrImage
End If
' Check if the start date and end date correspond to a valid range
' so that Start date is always prior to the end date
If IsDate(sStart_Date) AND IsDate(sEnd_Date) Then
If CDate(sStart_Date) > CDate(sEnd_Date) Then
bError = True
imgStart_Date = sErrImage
imgEnd_Date = sErrImage
End If
End If

If bError = False Then
' Create a recordset
Set Rs = Server.CreateObject("ADODB.RecordSet")

' Depending on the Mode, open the Recordset in eith Add or Edit mode
If sUpdateMode = "EDIT" Then
sSQL = "SELECT * FROM tEvents WHERE Event_ID=" & Request.Form("Event_ID")
Rs.Open sSQL, sDSN, adOpenKeySet, adLockPessimistic, adCmdText
Else
Rs.Open "tEvents", sDSN, adOpenKeySet, adLockPessimistic, adCmdTable
Rs.AddNew
Rs("Date_Added") = Now()
End If

' Populate the RecordSet fields
Rs("Start_Date") = CDate(Request.Form("START_DATE"))

' If the end date is blank, it equals start date
If Trim(sEnd_Date) <> "" Then
Rs("End_Date") = CDate(Request.Form("END_DATE"))
Else
Rs("End_Date") = CDate(Request.Form("START_DATE"))
End If

Rs("Start_Time") = Request.Form("START_TIME")
Rs("End_Time") = Request.Form("END_TIME")
Rs("Event_Title") = Request.Form("EVENT_TITLE")
Rs("Event_Details") = Request.Form("EVENT_Details")
Rs.Update

Rs.Close
Set Rs = Nothing

If sUpdateMode = "ADD" Then
sTitle = "Event Added"
Else
sTitle = "Event Updated"
End If
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Manohar Kamath">
<TITLE><% =sTitle %></TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF>
<H3><FONT FACE="Verdana"><% =sTitle %></FONT></H3>
<FONT SIZE=2 FACE="Verdana">

<P>
Thank you!
</P>
</FONT>

<!-- #include file="menu.inc" -->

</BODY>
</HTML>

<%
Else
Show_Form()
End If
End Sub
%>

Reply With Quote
  #4  
Old August 25th, 2003, 11:33 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Ok I've copy/pasted your code into an empty project of mine and I have to be honnest, the code is hard to read...

You're intermingling too much HTML code with ASP code, why aren't you making your life easier?

I take your health very seriously

Try not to make/put everything in one .asp page...its hard to debug!

Make your first .asp page, then add two buttons, ADD and EDIT

When the user clicks on the ADD button, call add.asp for example, which loads a nice new empty <form>...</form>

If the user clicks on the EDIT button then call edit.asp passing the ID in a <hidden> form field OR via the QueryString

This will greatly increase performance and the readability of your code.

Let me know what you think!

Sincerely

Vlince

Reply With Quote
  #5  
Old August 25th, 2003, 11:39 AM
thebloodletting thebloodletting is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 thebloodletting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

LOL...I wish I could do that Vince, but I'm a novice in this field. I used a ready made, free calendar for this whole thing. I'll attach the zip file here.

I'm really only wondering if I can still use the HTML ENCODE variable to make drop downs instead of using Text Fields where there are no options, just straight text (or HTML).

If you or anyone knows this and can provide an example of this for use in this form, please let me know.

I thank you Vince for assuming I know what the heck I'm talking about.
Attached Files
File Type: zip aspcalendar_v1.zip (48.7 KB, 287 views)

Reply With Quote
  #6  
Old August 25th, 2003, 11:41 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hehe ... :-)

I'll have a look at it and keep you noticed!
thanks!

Vlince

Reply With Quote
  #7  
Old August 25th, 2003, 12:19 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Did I say "keep you noticed" ???

I mean posted of course :-)


Anyway, I've tried looking again at your code and the code example and still don't know why your UPDATE isn't working...

Are you creating brand new ASP pages OR are you working with the ASP files from the .ZIP example you've given me?

My suggestion to you is DEBUG step by step making some Response.Write in critical area in your CODE until you figure out what the error is...

Good Luck ;-)
Hope this helps!
Sincerely


Vlince

Reply With Quote
  #8  
Old August 25th, 2003, 01:06 PM
thebloodletting thebloodletting is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 thebloodletting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

I do believe that I figured it out. Yes, I am using the ASP pages that came with the zip file and I have modified the addedit.asp page. this is what I did to get the AddTime field to be a dropdown instead of the static textfield:

FOR THE ADD START TIME PORTION, I TOOK OUT THE ASP CODE AND JUST LEFT IT WITH THE NAEM OF THE ACCESS DATABASE FIELD FOR THE NAME:

<TD VALIGN=TOP ALIGN=LEFT WIDTH=70%><FONT FACE=Verdana SIZE=2>
<select name="Start_Time">
<option value=""> Select a Start Time</option>
<option value="1 am">1 am</option>
<option value="2 am">2 am</option>
<option value="3 am">3 am</option>
<option value="4 am">4 am</option>
<option value="5 am">5 am</option>
<option value="6 am">6 am</option>
<option value="7 am">7 am</option>
<option value="8 am">8 am</option>
<option value="9 am">9 am</option>
<option value="10 am">10 am</option>
<option value="11 am">11 am</option>
<option value="12 noon">12 noon</option>
<option value="1 pm">1 pm</option>
<option value="2 pm">2 pm</option>
<option value="3 pm">3 pm</option>
<option value="4 pm">4 pm</option>
<option value="5 pm">5 pm</option>
<option value="6 pm">6 pm</option>
<option value="7 pm">7 pm</option>
<option value="8 pm">8 pm</option>
<option value="9 pm">9 pm</option>
<option value="10 pm">10 pm</option>
<option value="11 pm">11 pm</option>
<option value="12 midnight">12 midnight</option>
</select>
</FONT><% =imgStart_Date %></TD>

It works and it adds the time to the database. I thought I needed to be fancy with ASP to get it to do this, but I was mistaken.

Thank you Vlince for taking the time with me. Hopefully others will be able to use this information.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Need Help With HTML Encode and Select Form Fields Please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway