473,413 Members | 1,757 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,413 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 4015
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.