473,229 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,229 software developers and data experts.

Response.Write double quotes in JScript

Hi,

I have written a page to test a function of mine that strips non-English
accents and various other characters out of a given string. The function
itself (called 'StripAll' in the code below) now works fine.

However something else in the test page is not working, and it's starting to
bug me! If the user types a string containing double quotes into the
textbox, when the textbox is re-populated after the postback, any part of
the entered string *after* the first double quote is lost.

I'm wondering what I'm doing wrong here. It's just a minor point, but it's
getting annoying!

Any help appreciated,

TIA,

JON

PS The issue is presumably the RegExp in function
EscapeDoubleInvertedCommas.

------------------------------------------
<%@ LANGUAGE="JavaScript"%>
<%
var sourceString = "" + Request.Form("txtSourceString");
var defaultSourceString = "
Y &&&123~~~~45";

function RemoveDoubleInvertedCommas(sourceString)
{
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"");
}

function EscapeDoubleInvertedCommas(sourceString)
{
//trying to refill the textbox on postback with any inverted commas that
were typed in!
//NOT WORKING!
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"\"");
}
%>


<form method="post" id="form1" name="form1">

URL: <input name="txtSourceString" type="text" value="<% if (sourceString
!= "undefined") {Response.Write(EscapeDoubleInvertedCommas(sourceS tring))}
else {Response.Write(defaultSourceString)}%>" id="txtSourceString"
style="width:500px;" />
<br>
<input type="submit" name="btnTest" value="Test StripAll" id="btnTest" />
<br>

<hr>

Stripped version: <% if(sourceString != "undefined")
{Response.Write(StripAll(RemoveDoubleInvertedComma s(sourceString)));}%>
<br>
</form>
<%

function StripAccents(sourceString)
{
re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "a");

re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "A");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "c");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "C");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "e");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "E");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "i");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "I");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "n");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "N");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "o");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "O");

re = new RegExp("", "g");
sourceString = sourceString.replace(re, "ss");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "u");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "U");

re = new RegExp(("|"), "g");
sourceString = sourceString.replace(re, "y");

re = new RegExp(("|Y"), "g");
sourceString = sourceString.replace(re, "Y");

return sourceString;
}

function StripAll(sourceString)
{
sourceString = StripAccents(sourceString);

re = new RegExp((" "), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("_"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("&"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("~"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("'|;|:"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("\""), "g");
sourceString = sourceString.replace(re, "");

return sourceString;
}

%>

Jul 19 '05 #1
2 3995
Server.HTMLEncode the value. The problems is that you're ending up with
something like:

<input type="text" name="something" value="He said, "Hi how are you?"">

The browser will see the " before Hi and assume it is the end of the value.
By Server.HTMLEncoding it, you'll get:

<input type="text" name="something" value="He said, &quot;Hi how are
you?&quot;">

Ray at work

"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:OF**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have written a page to test a function of mine that strips non-English
accents and various other characters out of a given string. The function
itself (called 'StripAll' in the code below) now works fine.

However something else in the test page is not working, and it's starting
to
bug me! If the user types a string containing double quotes into the
textbox, when the textbox is re-populated after the postback, any part of
the entered string *after* the first double quote is lost.

I'm wondering what I'm doing wrong here. It's just a minor point, but
it's
getting annoying!

Any help appreciated,

TIA,

JON

PS The issue is presumably the RegExp in function
EscapeDoubleInvertedCommas.

------------------------------------------
<%@ LANGUAGE="JavaScript"%>
<%
var sourceString = "" + Request.Form("txtSourceString");
var defaultSourceString = "
Y &&&123~~~~45";

function RemoveDoubleInvertedCommas(sourceString)
{
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"");
}

function EscapeDoubleInvertedCommas(sourceString)
{
//trying to refill the textbox on postback with any inverted commas that
were typed in!
//NOT WORKING!
re = new RegExp(("\""), "g");
return sourceString.replace(re, "\"\"");
}
%>


<form method="post" id="form1" name="form1">

URL: <input name="txtSourceString" type="text" value="<% if (sourceString
!= "undefined") {Response.Write(EscapeDoubleInvertedCommas(sourceS tring))}
else {Response.Write(defaultSourceString)}%>" id="txtSourceString"
style="width:500px;" />
<br>
<input type="submit" name="btnTest" value="Test StripAll" id="btnTest" />
<br>

<hr>

Stripped version: <% if(sourceString != "undefined")
{Response.Write(StripAll(RemoveDoubleInvertedComma s(sourceString)));}%>
<br>
</form>
<%

function StripAccents(sourceString)
{
re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "a");

re = new RegExp("|||||", "g");
sourceString = sourceString.replace(re, "A");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "c");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "C");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "e");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "E");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "i");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "I");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "n");

re = new RegExp((""), "g");
sourceString = sourceString.replace(re, "N");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "o");

re = new RegExp(("|||||"), "g");
sourceString = sourceString.replace(re, "O");

re = new RegExp("", "g");
sourceString = sourceString.replace(re, "ss");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "u");

re = new RegExp(("|||"), "g");
sourceString = sourceString.replace(re, "U");

re = new RegExp(("|"), "g");
sourceString = sourceString.replace(re, "y");

re = new RegExp(("|Y"), "g");
sourceString = sourceString.replace(re, "Y");

return sourceString;
}

function StripAll(sourceString)
{
sourceString = StripAccents(sourceString);

re = new RegExp((" "), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("_"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("&"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("~"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("'|;|:"), "g");
sourceString = sourceString.replace(re, "");

re = new RegExp(("\""), "g");
sourceString = sourceString.replace(re, "");

return sourceString;
}

%>

Jul 19 '05 #2
Bingo! Nice one Ray!

:-)

JON
Jul 19 '05 #3

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

Similar topics

9
by: Ricardo | last post by:
Hi. How should I pass a " (doble-quote) character to response.write() in order for it to be sent to the output ? Thanks in advance for the help.
1
by: Thomas Henz | last post by:
Hi there, I want to do: response.write("bla bla bla "in quotes" bla bla") How do I show the quotes on the screen in asp like I have to do \" in php? Thanks,
13
by: TinyTim | last post by:
I'm a newbie at ASP & HTML. It seems that when you use server side code and you're going to return a customized HTML form with several fields and labels, you have to do an extensive amount of...
4
by: Dennis M. Marks | last post by:
I generate a SELECT list dynamically by taking items from a table. I have DOCUMENT.WRITE statements that write a combination of literals and variables including < and > characters. The HTML seems...
35
by: Eitan | last post by:
Hello, How can I write a line (with carriage return + line feed) to the client ? response.write("abcd"), continue the last line, and doesn't put cr+lf. response.writeLn is illegal syntax... ...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
4
by: nsj | last post by:
How shall i use quotation marks within another in asp.net?
5
by: coldstar | last post by:
In an ASP Querystring, how do I include the double quotes in the code below at "1.0" part as text in my string? I have tried ""1.0"" and almost everything else but can't get it to work. I need...
3
by: Alan Mailer | last post by:
Ok, I've looked for an answer for this, because I'm sure it's been asked a thousand times... but no luck... so here goes. Imagine I want to create a NodeList based on an XPath statement. The...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.