473,699 Members | 2,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript Replace() Method

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(t his.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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javas cript">

function stringReplace(f orm) {
var replaceStr = form.textfield1 .value
var pattern = /\'/g;
form.textfield1 .value = replaceStr.repl ace(pattern, "''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_ redirect.asp">
<p>fname:
<input type="text" name="textfield 1" size="20">
</p>
<p>lname:
<input type="text" name="textfield 2" size="20">
</p>
<p>
<input onclick="return stringReplace(f orm)" type="submit" name="Submit" value="Submit">
</p>

</form>
</body>
</html>

Jul 19 '05 #1
12 8157
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****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.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(t his.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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javas cript">

function stringReplace(f orm) {
var replaceStr = form.textfield1 .value
var pattern = /\'/g;
form.textfield1 .value = replaceStr.repl ace(pattern, "''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_ redirect.asp">
<p>fname:
<input type="text" name="textfield 1" size="20">
</p>
<p>lname:
<input type="text" name="textfield 2" size="20">
</p>
<p>
<input onclick="return stringReplace(f orm)" type="submit" name="Submit" value="Submit"> </p>

</form>
</body>
</html>

Jul 19 '05 #2
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
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(t his.form)"
Just skip the word "return" like this:

onclick = "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.


You should not ask a clientside question on this NG, really.

It is like asking the bus company how to repair your own car,
because you planned to go by bus first or next time.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3
How would I check for all textfields, not just the first one.

The blank in the code below would be where the textfield name would go but can I generalize this name? I've tried text, type, input...but I'm not sure what JavaScript name would go here. Also, If I use onblur, can I use the same function or do I have to make a function for every textfeild--this would be too much.

function stringReplace(f orm) {
var replaceStr = form.______.val ue
var pattern = /\'/g;
form._______.va lue = replaceStr.repl ace(pattern, "''");
}
</script>

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****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.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(t his.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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javas cript">

function stringReplace(f orm) {
var replaceStr = form.textfield1 .value
var pattern = /\'/g;
form.textfield1 .value = replaceStr.repl ace(pattern, "''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_ redirect.asp">
<p>fname:
<input type="text" name="textfield 1" size="20">
</p>
<p>lname:
<input type="text" name="textfield 2" size="20">
</p>
<p>
<input onclick="return stringReplace(f orm)" type="submit" name="Submit"

value="Submit">
</p>

</form>
</body>
</html>


Jul 19 '05 #4
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
How would I check for all textfields, not just the first one.

The blank in the code below would be where the textfield name would go
but can I generalize this name? I've tried text, type, input...but I'm
not sure what JavaScript name would go here. Also, If I use onblur,
can I use the same function or do I have to make a function for every
textfeild--this would be too much.

function stringReplace(f orm) {
var replaceStr = form.______.val ue
var pattern = /\'/g;
form._______.va lue = replaceStr.repl ace(pattern, "''");
}
</script>

Thank you in advance for your help!


This is all clientside code.
Why would you want to use a serverside NG?

Please follow up elsewhere.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #5
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.CreateOb ject ("ADODB.Connect ion");
//Database.Open ("dsn=INTRANET" );
Database.Open ("driver=SQL .....

// Create a recordset of all information in this table.
DirectoryRecord Set = Server.CreateOb ject ("ADODB.RecordS et");

// Construct the SQL Query
strSQL = "INSERT INTO " +
"ProductEvalReq uest " +
"(RequestorName , RequestorEmail, OutsideSalesRep Name, OutsideSalesRep Email, InsideSalesRepN ame, InsideSalesRepE mail, " +
"ReportingMgrNa me, ReportingMgrEma il, CustomerName, CustomerEmail, DescProduct, ProductDollarAm t, " +
"ValueEval, DealBook, DealStage, ApprxStorageOpp , AcctRev , DateEval, DurationEval, Approval) " +
"VALUES " +
"('" + replace(RN) + "', " +
"'" + replace(RE) + "', " +
"'" + replace(Request .Form("txtOutsi deSalesRepName" )) + "', " +
"'" + replace(Request .Form("txtOutsi deSalesRepEmail ") + "', " +
"'" + replace(Request .Form("txtInsid eSalesRepName") + "', " +
"'" + replace(Request .Form("txtInsid eSalesRepEmail" ) + "', " +
"'" + replace(Request .Form("txtRepor tingMgrName") + "', " +
"'" + replace(Request .Form("txtRepor tingMgrEmail") + "', " +
"'" + replace(Request .Form("txtCusto merName") + "', " +
"'" + replace(Request .Form("txtCusto merEmail") + "', " +
"'" + replace(Request .Form("txtDescP roduct") + "', " +
"'" + replace(Request .Form("txtProdu ctDollarAmt") + "', " +
"'" + replace(Request .Form("txtValue OfDeal") + "', " +
"'" + replace(Request .Form("txtDealE xpBook") + "', " +
"'" + replace(Request .Form("txtStage Deal") + "', " +
"'" + replace(Request .Form("txtAppro xStorageOpp") + "', " +
"'" + replace(Request .Form("txtAcctR ev") + "', " +
"'" + replace(Request .Form("txtDateE val") + "', " +
"'" + replace(Request .Form("txtDurat ionEval") + "', " +
"'" + replace(Request .Form("txtAppro val") + "')";


//Response.Write ("<p>" + strSQL + "\n");

//Response.Write( replace(string) );

DirectoryRecord Set.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****@discuss ions.microsoft. com> wrote in message
news:9B******** *************** ***********@mic rosoft.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(t his.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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javas cript">

function stringReplace(f orm) {
var replaceStr = form.textfield1 .value
var pattern = /\'/g;
form.textfield1 .value = replaceStr.repl ace(pattern, "''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_ redirect.asp">
<p>fname:
<input type="text" name="textfield 1" size="20">
</p>
<p>lname:
<input type="text" name="textfield 2" size="20">
</p>
<p>
<input onclick="return stringReplace(f orm)" type="submit" name="Submit"

value="Submit">
</p>

</form>
</body>
</html>


Jul 19 '05 #6
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
Do you know of a JavaScript NG at MSDN? I tried to look for one but
can't find it.


[please do not toppost on usenet]

Dunno about MDSDN, will not touch it.

You are here on usenet, venerable old usenet with many NGs.

Try:

comp.lang.javas cript

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #7
Ok, that's Google, right? Thanks.

"Evertjan." wrote:
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
Do you know of a JavaScript NG at MSDN? I tried to look for one but
can't find it.


[please do not toppost on usenet]

Dunno about MDSDN, will not touch it.

You are here on usenet, venerable old usenet with many NGs.

Try:

comp.lang.javas cript

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 19 '05 #8
microsoft.publi c.scripting.jsc ript

Barnes wrote:
Do you know of a JavaScript NG at MSDN? I tried to look for one but
can't find it.

Your help is greatly appreciated.

"Evertjan." wrote:
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
How would I check for all textfields, not just the first one.

The blank in the code below would be where the textfield name would
go
but can I generalize this name? I've tried text, type, input...but
I'm
not sure what JavaScript name would go here. Also, If I use onblur,
can I use the same function or do I have to make a function for
every textfeild--this would be too much.

function stringReplace(f orm) {
var replaceStr = form.______.val ue
var pattern = /\'/g;
form._______.va lue = replaceStr.repl ace(pattern, "''");
}
</script>

Thank you in advance for your help!


This is all clientside code.
Why would you want to use a serverside NG?

Please follow up elsewhere.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #9
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
microsoft.publi c.inetserver.as p.general:
"Evertjan." wrote:
=?Utf-8?B?QmFybmVz?= wrote on 02 jul 2004 in
[please do not toppost on usenet]

Dunno about MDSDN, will not touch it.

You are here on usenet, venerable old usenet with many NGs.

Try:

comp.lang.javas cript
Ok, that's Google, right? Thanks.


No, it is Usenet. Usenet presedes the Web by many years.

You could access that via the web and Google, but you have much more
flexiblility using a dedicated News server like Xnews or Agent.

And please do not respond with an answer on top of my mail.
That topposting is "not done" on usenet.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9185
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4389
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.