 |
BOOK: Beginning Dreamweaver MX/MX 2004 MX ISBN: 978-0-7645-4404-0; MX 2004 ISBN: 978-0-7645-5524-4  | This is the forum to discuss the Wrox book Beginning Dreamweaver MX by Charles E. Brown, Imar Spaanjaars, Todd Marks; ISBN: 9780764544040 |
Please indicate which version of the book you are using when posting questions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Dreamweaver MX/MX 2004 MX ISBN: 978-0-7645-4404-0; MX 2004 ISBN: 978-0-7645-5524-4 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 20th, 2003, 09:53 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Page 522 - 525
Hi,
I have followed all the instrunctions very carefully. But my code still doesn't work. My Create button doesn't call validateForm() at all. I have tripple checked everything and it is same as of sample code and the book.
Following is my copy of my cretaeEvent.asp.
Thanks for reading it and helping me out.
Omer
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="Administrators"
MM_authFailedURL="../login.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_connTheSoccerSite_STRING
MM_editTable = "Events"
MM_editRedirectUrl = "showEvents.asp"
MM_fieldsStr = "Title|value|Summary|value|EventDescription|value| Category|value|StartDate|value|EndDate|value"
MM_columnsStr = "Title|',none,''|Summary|',none,''|EventDescriptio n|',none,''|Category|none,none,NULL|StartDate|',no ne,NULL|EndDate|',none,NULL"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim rsCategories
Dim rsCategories_numRows
Set rsCategories = Server.CreateObject("ADODB.Recordset")
rsCategories.ActiveConnection = MM_connTheSoccerSite_STRING
rsCategories.Source = "SELECT * FROM Categories ORDER BY Description ASC"
rsCategories.CursorType = 0
rsCategories.CursorLocation = 2
rsCategories.LockType = 1
rsCategories.Open()
rsCategories_numRows = 0
%>
<html>
<head>
<title>GlobalSoccerEvents.com - Your Source for Soccer Events Around the Globe</title>
<script language="JavaScript" type="text/JavaScript">
function validateForm()
{ alert('start of fucntion');
//create a reference to Title textbox
var formField = document.form1.Title;
//see if user typed anything in field
if (formField.value == '')
{ alert('Please enter value for Title');
formField.focus();
return false;
}
//create reference to Summary text area
formField = document.form1.Summary;
if (formField.value == '')
{ alert('Please enter value for Summary');
formField.focus();
retrun false;
}
else
{ //check for its length, we accept 250 chars max
if (formField.value.length > 250)
{ alert('You cannot have more than 250 characters in Summary field');
formField.focus();
return false;
}
}
//create reference to EventDescription text area
formField = document.form1.EventDescription;
if (formField.value == '' )
{ alert('The Event Description cannot be empty');
formField.focus();
return false;
}
//create reference to StartDate
formField = document.form1.StartDate;
if (formField.value = '')
{ alert('Start Date cannot be empty');
formField.focus;
return false;
}
//check start date for a valid pattern, like 12/12/2003 or 12-20-2003
var objRegExp = /^\d{1, 2}(\-|\/|\.)\d{1, 2}\1\d{4}$/
if (!objRegExp.test(formField.value))
{ alert('Start Date is not a valid date');
formField.focus;
return false;
}
//create a ref to EndDate
formField = document.form1.EndDate;
if (formField == '')
{ alert('End Date cannot be blank');
formField.focus();
return false;
}
//check end date for a valid pattern, like 12/12/2003 or 12-20-2003
var objRegExp = /^\d{1, 2}(\-|\/|\.)\d{1, 2}\1\d{4}$/
if (!objRegExp.test(formField.value))
{ alert('End Date is not a valid date');
formField.focus;
return false;
}
//if there are no errors, we can return true
return true;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Dim sBackgroundColor
If Len(Request.Cookies("BackgroundColor")) > 0 Then
sBackgroundColor = Request.Cookies("BackgroundColor")
Else
sBackgroundColor = "#FFFFFF"
End If
Dim iTheme
If Len(Request.Cookies("SiteTheme")) > 0 Then
iTheme = Request.Cookies("SiteTheme")
Else
iTheme = 1 ' Our default theme
End If
Dim sBadge
If Len(Request.Cookies("SelectedBadge")) > 0 Then
sBadge = Request.Cookies("SelectedBadge")
Else
sBadge = "logo"
End If
%>
<link href="../styles/mainStyles<%=iTheme%>.css" rel="stylesheet" type="text/css">
</head>
<body style="background-color: <%=sBackgroundColor%>">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td>
<img src="../images/<%=sBadge%>.gif" name="imgDefaultBadge" id="imgDefaultBadge"></td>
<td>
<table border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td><a href="../home.asp" id="home">Home</a></td>
<td> </td>
<td><a href="../events.asp" id="events">Events</a></td>
<td> </td>
<%
MM_authorizedUsers="Administrators,Members"
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
%>
<td><a href="../mySite.asp" id="mysite">My Site</a></td>
<td> </td>
<%
End If
End If
%>
<%
MM_authorizedUsers="Administrators"
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
%>
<td><a href="admin.asp" id="admin">Admin</a></td>
<td> </td>
<%
End If
End If
%>
<td><a href="../login.asp" id="login">Login</a></td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<script language="JavaScript" type="text/javascript">
var sPageName = '<%=Request.ServerVariables("SCRIPT_NAME")%>';
sPageName = sPageName.substr(sPageName.lastIndexOf('/') + 1 ).toLowerCase();
sPageName = sPageName.substr(0, sPageName.lastIndexOf('.'));
if (document.getElementById(sPageName))
{
document.getElementById(sPageName).style.fontWeigh t = 'Bold';
document.getElementById(sPageName).style.fontSize = '14pt';
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td><h2>
Create a New Event</h2></td>
</tr>
<tr>
<td>
<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Title:</td>
<td>
<input name="Title" type="text" value="" size="32" maxlength="75">
</td>
</tr>
<tr>
<td nowrap align="right" valign="top">Summary:</td>
<td valign="baseline">
<textarea name="Summary" cols="50" rows="5"></textarea>
</td>
</tr>
<tr>
<td nowrap align="right" valign="top">Event Description:</td>
<td valign="baseline">
<textarea name="EventDescription" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Category:</td>
<td>
<select name="Category">
<%
While (NOT rsCategories.EOF)
%>
<option value="<%=(rsCategories.Fields.Item("ID").Value)%> "><%=(rsCategories.Fields.Item("Description").Valu e)%></option>
<%
rsCategories.MoveNext()
Wend
If (rsCategories.CursorType > 0) Then
rsCategories.MoveFirst
Else
rsCategories.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Start Date:</td>
<td>
<input type="text" name="StartDate" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">End Date:</td>
<td>
<input type="text" name="EndDate" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td>
<input name="btnCreate" type="submit" onClick="return validateForm();" value="Create Event">
<input name="btnCancel" type="button" onClick="if (confirm('Are you sure you want to cancel?'))
document.location.href=' showEvents.asp';" value="Cancel">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</td>
</tr>
<tr>
<td align="center">
<br>
<br>
<br>
</td>
</tr>
</table>
</body>
</html>
<%
rsCategories.Close()
Set rsCategories = Nothing
%>
|
|

July 20th, 2003, 10:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Omer,
Are you by any chance running a product like Norton Internet Security? If so, you may need to disable it. One of its features (the add-blocking feature if I recall correctly) adds some JavaScript that blocks an alert message when you get a JavaScript error. That way, any error in your code is ignored and the page submits without the actual validation.
As soon as you turn the feature off (if you had it on, of course), reloading the page will give you some more detailed error information. (If it still doesn't show up, uncheck Disable Script debugging and check Display a notification about every script error on the Advanced tab of your Internet Explorer Options dialog.
When you now refresh the page, the code will crash on the following section:
Code:
//create reference to Summary text area
formField = document.form1.Summary;
if (formField.value == '')
{ alert('Please enter value for Summary');
formField.focus();
retrun false;
}
And there you have it: retrun is not a valid JavaScript statement. Change it to return and your page will work fine.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

July 20th, 2003, 10:39 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Thanks for the correction of Return statement.
I do have Norton Antivirus install and it is version is 7 Corporate Edition. But I don't think it stops any Pop Up Adds, etc. But I will double check.
My Cancel button works fine. It shows me Alert Message properly.
For testing, I changed my Create button. Instead of calling Function, I put same code which I have for Cancel button and it worked properly. So I think it is not calling Function at all.
Any idea why?
Thanks,
Omer
|
|

July 20th, 2003, 10:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
To be honest, no. I copied and pasted your code in a new page, fixed the return statement and then the page worked OK.
Can you take a look at the source of your page (that is, not the ASP source but the source in the browser). Does it have something like this in the page:
<script language="JavaScript">
<!--
Code:
function SymError()
{
return true;
}
window.onerror = SymError;
//-->
</script>
If so, any errors are ignored for the reasons I mentioned earlier.
If this doesn't help, can you post the code for the entire page again (or send it to me through e-mail; whatever you think works best).
Also, can you describe what goes wrong? I.e., do you get any error at all??
Cheers,
Imar
Quote:
quote:Originally posted by omermalik
My Cancel button works fine. It shows me Alert Message properly.
For testing, I changed my Create button. Instead of calling Function, I put same code which I have for Cancel button and it worked properly. So I think it is not calling Function at all.
Any idea why?
|
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

July 20th, 2003, 11:03 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar. Fixing the return statement fixed the problem.
Now I know one more thing, typing errors even inside the function will cause uncertain errors.
Thanks for your help.
Omer
|
|

July 20th, 2003, 11:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, typos in script code are even worse than typos in plain text. Fortunately, the script debugger of your browser will inform you of most errors.
Glad it worked out.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |