B
Barnes
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>
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>