Here is the server side script that you were asking me about. This is generation an "Object undefined" error and I can't seem to correct it. If you can offer help on this, then I won't have to do the replace method in JavaScript on the client side.
-------------------------------------------------
function replace(string)
{
var pattern = /\'/g;
var newString = string.replace(pattern, "''");
return newString;
}
// Create a database connection.
Database = Server.CreateObject ("ADODB.Connection");
//Database.Open ("dsn=INTRANET");
Database.Open ("driver=SQL .....
// Create a recordset of all information in this table.
DirectoryRecordSet = Server.CreateObject ("ADODB.RecordSet");
// Construct the SQL Query
strSQL = "INSERT INTO " +
"ProductEvalRequest " +
"(RequestorName, RequestorEmail, OutsideSalesRepName, OutsideSalesRepEmail, InsideSalesRepName, InsideSalesRepEmail, " +
"ReportingMgrName, ReportingMgrEmail, CustomerName, CustomerEmail, DescProduct, ProductDollarAmt, " +
"ValueEval, DealBook, DealStage, ApprxStorageOpp, AcctRev , DateEval, DurationEval, Approval) " +
"VALUES " +
"('" + replace(RN) + "', " +
"'" + replace(RE) + "', " +
"'" + replace(Request.Form("txtOutsideSalesRepName")) + "', " +
"'" + replace(Request.Form("txtOutsideSalesRepEmail") + "', " +
"'" + replace(Request.Form("txtInsideSalesRepName") + "', " +
"'" + replace(Request.Form("txtInsideSalesRepEmail") + "', " +
"'" + replace(Request.Form("txtReportingMgrName") + "', " +
"'" + replace(Request.Form("txtReportingMgrEmail") + "', " +
"'" + replace(Request.Form("txtCustomerName") + "', " +
"'" + replace(Request.Form("txtCustomerEmail") + "', " +
"'" + replace(Request.Form("txtDescProduct") + "', " +
"'" + replace(Request.Form("txtProductDollarAmt") + "', " +
"'" + replace(Request.Form("txtValueOfDeal") + "', " +
"'" + replace(Request.Form("txtDealExpBook") + "', " +
"'" + replace(Request.Form("txtStageDeal") + "', " +
"'" + replace(Request.Form("txtApproxStorageOpp") + "', " +
"'" + replace(Request.Form("txtAcctRev") + "', " +
"'" + replace(Request.Form("txtDateEval") + "', " +
"'" + replace(Request.Form("txtDurationEval") + "', " +
"'" + replace(Request.Form("txtApproval") + "')";
//Response.Write ("<p>" + strSQL + "\n");
//Response.Write(replace(string));
DirectoryRecordSet.Open (strSQL, Database);
%>
-------------
Thank you in advance for your help!!
"Alan Howard" wrote:
You could call your stringReplace method as the onBlur handler for each
control needing it - but your attempt to do this server-side is the correct
way approach - show us your server-side code that wasn't working.
Alan
"Barnes" <Ba****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com... Does anyone know of a good way to use the JavaScript string.replace()
method in an ASP form?
Here is the scenario:
I have a form that cannot accept apostrophes. I want to use the replace()
so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like
apostrophes being sent to database.
I've tried to do this on the server side in the SQL area of the ASP page
by writing a function (with some great help) but I can seem to get it to work. That's is why I want do try on the
client side.
I've already made an attempt and the replace() method does work. The
problem is the form has an Action = "bla.asp" This is the redirect page. But the page doesn't redirect because in the
Input tag, I have an onclick = "return stringReplace(this.form)"
So here is my delimma--I want to be able to replace the character before
it redirects to the other .asp page.
Any ideas? Below is the code:
---------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function stringReplace(form) {
var replaceStr = form.textfield1.value
var pattern = /\'/g;
form.textfield1.value = replaceStr.replace(pattern, "''");
}
</script>
</head>
<body>
<form name="form1" method="post" action="JStest_redirect.asp">
<p>fname:
<input type="text" name="textfield1" size="20">
</p>
<p>lname:
<input type="text" name="textfield2" size="20">
</p>
<p>
<input onclick="return stringReplace(form)" type="submit" name="Submit"
value="Submit"> </p>
</form>
</body>
</html>