473,396 Members | 2,076 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,396 software developers and data experts.

" in textfields

I'm writing innerHTML for a text field.

Sometime the textfield has double quotes in them.

value_=value_.replace(/"/g,'\\"');
var content = '<input type="text" name="'+name_+'" size="'+size_+'"
value="'+value_+'">';

I'm not sure why that doesn't work, but it doesn't! I'm missing
something simple, somewhere.

Jeff
Jun 27 '08 #1
6 1138
Jeff schreef:
I'm writing innerHTML for a text field.

Sometime the textfield has double quotes in them.

value_=value_.replace(/"/g,'\\"');
Hi,

Unless you really know what you are doing, I advise you to simply use
the codes for special HTML chars.

eg:

<script type="text/javascript">
var org = "test single' and double\" endtest";
// replace "
replaced = org.replace(/\"/g,'&quot;');
// replace '
replaced = replaced.replace(/\'/g,''');

var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);

</script>

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.

No need to dive into that when you have &quot; and ' to do the work
for you.

Regards,
Erwin Moller

var content = '<input type="text" name="'+name_+'" size="'+size_+'"
value="'+value_+'">';

I'm not sure why that doesn't work, but it doesn't! I'm missing
something simple, somewhere.

Jeff
Jun 27 '08 #2
Erwin Moller wrote:
<script type="text/javascript">
var org = "test single' and double\" endtest";
// replace "
replaced = org.replace(/\"/g,'&quot;');
// replace '
replaced = replaced.replace(/\'/g,''');

var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);

</script>

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.
Can't be done with backslashes; even \x22 or \u0022 are not accepted.
&quot; is the only way.

--
Bart
Jun 27 '08 #3
Bart Van der Donck wrote:
Erwin Moller wrote:
><script type="text/javascript">
var org = "test single' and double\" endtest";
// replace "
replaced = org.replace(/\"/g,'&quot;');
// replace '
replaced = replaced.replace(/\'/g,''');

var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);

</script>

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.

Can't be done with backslashes; even \x22 or \u0022 are not accepted.
&quot; is the only way.
Thanks!

Jeff
>
--
Bart
Jun 27 '08 #4
Bart Van der Donck wrote:
Erwin Moller wrote:
>[escape the value of `replaced' for Valid markup]
var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);
[...]

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.

Can't be done with backslashes; even \x22 or \u0022 are not accepted.
&quot; is the only way.
`&#x22;', `"', or using other DOM mutator methods are other ways.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #5
Thomas 'PointedEars' Lahn schreef:
Bart Van der Donck wrote:
>Erwin Moller wrote:
>>[escape the value of `replaced' for Valid markup]
var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);
[...]

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.
Can't be done with backslashes; even \x22 or \u0022 are not accepted.
&quot; is the only way.

`&#x22;', `"', or using other DOM mutator methods are other ways.
PointedEars
Hi Thomas and Bart,

When Bart wrote that it couldn't be done, I had this feeling he was wrong.
I am positive I did it earlier, I thought.
So I retried, and was unsuccesfull.
So I looked up some old code where I did it, only to find out I didn't
do it that way. :-)
I weaseled out: writing the HTML, then some JavaScript that filled the
value. :-/

Anyway, writing HTML with formelements like that is ugly IMHO.
Since all my pages are produced by PHP I seldom need document.write,
most/all can be done at the server.

Regards,
Erwin Moller
Jun 27 '08 #6
Erwin Moller wrote:
Thomas 'PointedEars' Lahn schreef:
>Bart Van der Donck wrote:
>>Erwin Moller wrote:
[escape the value of `replaced' for Valid markup]
var content = '<br><input type="text" name="bla" size="30"
value="'+replaced+'">';

document.write(content);
[...]

You can do this with adding backslashes, but things gets complicated
very fast, especially when passing the strings around. Things get worse
when you also do this serverside.
Can't be done with backslashes; even \x22 or \u0022 are not accepted.
&quot; is the only way.

`&#x22;', `"', or using other DOM mutator methods are other ways.
PointedEars

Hi Thomas and Bart,

When Bart wrote that it couldn't be done, I had this feeling he was wrong.
I am positive I did it earlier, I thought.
So I retried, and was unsuccesfull.
So I looked up some old code where I did it, only to find out I didn't
do it that way. :-)
I weaseled out: writing the HTML, then some JavaScript that filled the
value. :-/

Anyway, writing HTML with formelements like that is ugly IMHO.
Since all my pages are produced by PHP I seldom need document.write,
most/all can be done at the server.
The trend is the other way, not with document.write but with either
innerHTML or DOM methods.

Say we have a large table of data and you just want to edit an item
here and there. It's easier for the user if he can click on the item he
wants to edit and have that replaced with a textfield or some such and
the updates would be returned to the server in the background using
AJAX. At least that is what I was doing... simple stuff...

Jeff

Regards,
Erwin Moller
Jun 27 '08 #7

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

Similar topics

3
by: R.G. Vervoort | last post by:
I would like to select an option in a pulldown, select a record in a mysql database depending on the pulldown selection and then put the data from the record in the textfields. I can retrieve...
1
by: Filips Benoit | last post by:
Dear All, After copying a record using an Stored procedure all textfields (nvarchar) has max lenght ! See VBA-code and SP below VBA-code tos execute SP
1
by: Ed | last post by:
Hi, I have an html page with a div element within a form for dynamically creating textfields. The problem is when I click a link on the page, or the submit button, then click the back button,...
1
by: Rich Wahl | last post by:
Ok, This may sound like a noob question, but I have an application, that asks the user to fill in fields from a pre-generated list of possibilities. And upon clicking submit, the user is...
2
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem with retriving "\" backslash , In my javascript client side page , ill get the response from the server side , the response will contain some url like...
0
by: chandutp | last post by:
hi i am new to this forum can i populate datagrid items of asp page to another asp page having textfields. in this datagrid userId is the index key by which it referenced.and i am using edit...
1
by: eureka | last post by:
Hi folks, I am working on a webapplication using Jsp and JS. On my main Jsp(Jsp1) I have a table which is created dynamically inside a <divand contains all the backend-table's records as rows,...
3
by: bravephantom | last post by:
In my project "scientific calculator", im using 2 textfields in my GUI app. the problem now (or actually what i dislike) is the user has to use the 2 textfields even if he needs a function of only 1...
4
faugustin
by: faugustin | last post by:
Hi, I have a problem. I have av form with textfields, textareas and a vector type fieldset of checkboxes. Everything but the checkboxes works fine, they result in "array" in the field in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.