473,395 Members | 1,484 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,395 software developers and data experts.

body.innerHTML issue

I'm having a problem with apostrophes & quotes when using body.innerHTML.

With the statement: bodyText = document.body.innerHTML

If there was a Form object on my page such as:
<input name="email" type="text" id="email">

bodyText transilates it into
<input name=email type=text id=email>

Is there anything i can do to fix this?
Thanks!
Jul 23 '05 #1
4 3034
> bodyText transilates it into
<input name=email type=text id=email>

Is there anything i can do to fix this?


You need to escape it.

This is most easly done with regular expressions (I believe)

bodyText = bodyText.replace(/\"/g,"\\\"");

should work

Jul 23 '05 #2
Reed wrote:
I'm having a problem with apostrophes & quotes when
using body.innerHTML.

With the statement: bodyText = document.body.innerHTML

If there was a Form object on my page such as:
<input name="email" type="text" id="email">

bodyText transilates it into
<input name=email type=text id=email>
You have only tired that on one browser. Mozilla and Opera each produce
distinct output form innerHTML (as do Konqueror/Safari and IceBrowser).
Is there anything i can do to fix this?


No, the innerHTML property reports a string constructed as a normalised
representation of the underlying DOM and any one browser will produce
what it produces, while different browsers (and browser versions) will
produce a different interpretation. Particularly when it comes to
quotes, apostrophise and the case of tag names and attribute names.

Richard.
Jul 23 '05 #3
Vincent van Beveren wrote:
> bodyText transilates it into
> <input name=email type=text id=email>
>
> Is there anything i can do to fix this?


You need to escape it.

This is most easly done with regular expressions (I believe)

bodyText = bodyText.replace(/\"/g,"\\\"");

should work


That works if you already have the string. It doesn't do what the op is
wanting to do though. Try it out.

What the OP is wanting is to read the innerHTML and get the quoted value
back from the browser, which it is normalizing. To get the actual text
of it, with quotes and all, look into the HTTPRequestObject or the JAVA
component listed in the FAQ
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #4
Richard Cornford wrote:
Reed wrote:
I'm having a problem with apostrophes & quotes when
using body.innerHTML.

With the statement: bodyText = document.body.innerHTML

If there was a Form object on my page such as:
<input name="email" type="text" id="email">

bodyText transilates it into
<input name=email type=text id=email>
Is there anything i can do to fix this?


No, the innerHTML property reports a string constructed as a normalised
representation of the underlying DOM and any one browser will produce
what it produces, while different browsers (and browser versions) will
produce a different interpretation. Particularly when it comes to
quotes, apostrophise and the case of tag names and attribute names.

Richard.


The thing to do to fix it is to not rely on attempting to parse the
contents of innerHTML. Instead, use the DOM accessor methods to obtain the
properties of the elements you want.

ie - document.getElementById('email'); to obtain a specific reference to
that input, or document.getElementsByTagName('input'); to obtain a
collection of all <input> tags, etc.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #5

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

Similar topics

7
by: KK | last post by:
Please help! I am currently experiencing a bug in Safari v125.9. When I modify the value of form input box and then get the innerHTML property of the surrounding div object - I am returned the...
14
by: christopher.secord | last post by:
Can someone please tell me why this works: document.body.innerHTML = "<table><tr><th>one</th></tr><tr><td>two</td></tr></table>"; But this does not work: document.body.innerHTML =...
10
by: Richard Steele | last post by:
Can anyone help me I am developing an application runs on a PC (client) only. For graphical reasons it was decided that the content would be displayed in a Browser that is embedded in a Windows...
1
by: lwhitb1 | last post by:
I have been trying to load a javascript function from the body onload html tag, but I only want the function to load the first time the page is loaded: I have investigated but haven't found...
2
by: sveinn | last post by:
Hi all, I've read through this group searching for an answear about this problem. Few have come close but not quite what I need. My problem is this: I'm using Ajax to fetch a new table with...
6
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I...
3
by: andrej.kaurin | last post by:
I need to put all body content into wrapper when page is loaded. Via javascript of course. Initial DOM <body> <div> <p>Some text</p> <p>More text</p> </div>
3
by: Sunny | last post by:
Hi, Can someone tell me, How to load the Body Html from a text file that contains javascript. to Manage my files I am creating an Index Page. <html> <head> <meta http-equiv="content-type"...
6
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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:
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...

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.