I'm having a problem with apostrophes & quotes when using body.innerHTML.
With the statement: bodyText = document.body.i nnerHTML
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! 4 3053
> 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.replac e(/\"/g,"\\\"");
should work
Reed wrote: I'm having a problem with apostrophes & quotes when using body.innerHTML.
With the statement: bodyText = document.body.i nnerHTML
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.
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.replac e(/\"/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 HTTPRequestObje ct or the JAVA
component listed in the FAQ
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Richard Cornford wrote: Reed wrote: I'm having a problem with apostrophes & quotes when using body.innerHTML.
With the statement: bodyText = document.body.i nnerHTML
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.getEle mentById('email '); to obtain a specific reference to
that input, or document.getEle mentsByTagName( 'input'); to obtain a
collection of all <input> tags, etc.
--
| Grant Wagner <gw*****@agrico reunited.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 original
form value not the changed value!
Has anyone else encountered this?
Cheers.
|
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 = "<table><tr>";
document.body.innerHTML = document.body.innerHTML +
"<th>one</th></tr><tr><td>two</td></tr></table>";
|
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 Forms application (VS net 2003) c#
I have a Windows Form that uses a webbrowser (AxWebBrowser) )to display
html derived from internal classes that builds data from a database. The
HTML displays correctly. The HTML is built at runtime and the...
|
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 anything that works..
I thought about cookies, but what if the user's disable them?
My code:
//I want to call the Toggle function below only on the 1st time the
page is loaded:
|
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 input
boxes. I then take
the innerHTML from my <div> and add the new table to the existing
one/s.
What happens in FireFox is that all values in other tables input boxes
| |
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 am a total newbie
but the answer was not immediately obvious to me here.
so.. problem:
declaring doctype as xhtml will prevent myDiv.innerHtml=val from
working.
suggested solution:
|
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>
|
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" content="text/html; charset=utf-8"/>
<title></title>
|
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 exactly matches
the contents of the div with one exception.
It seems that whenever the code includes a tag which uses the forward
slash against the closing bracket (say the break tag ..... />) that
the browser, or HTML, or javascript, or...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |