468,512 Members | 1,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 3775
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Henz | last post: by
4 posts views Thread by Dennis M. Marks | last post: by
35 posts views Thread by Eitan | last post: by
6 posts views Thread by Mark | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.