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

Assign entity to form text trouble

It would seem that when I assign an HTML entity to a form text input
using "inline" javascript that it will display properly. But when
trying to set it via a function call, the entity text shows in the
field instead of the symbol it represents. The following example
produces these results on Opera 8.5 and IE 6.0

I am expecting the same results whichever way I set the contents of
"myText". Why, when choosing "function" does "&copy" show in the field
instead of the copy symbol? If there is something obviously wrong... I
cannot see it. Any comments are appreciated.

<head>
<title>My Test</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function set_it(obj)
{
obj.form.myText.value='&copy;';
}
</script>
<form action="#" method="get">
<input name="myText" type="text" value="&copy;" />
<input name="btn01" type="button" value="inline"
onClick="this.form.myText.value='&copy;';"/>
<input name="btn02" type="button" value="function"
onClick="set_it(this);"/>
</form>
</body>
</html>

Nov 2 '05 #1
1 1794
go****@quietbay.net wrote:
It would seem that when I assign an HTML entity to a form text
input using "inline" javascript that it will display properly.
But when trying to set it via a function call, the entity text
shows in the field instead of the symbol it represents. The
following example produces these results on Opera 8.5 and
IE 6.0

I am expecting the same results whichever way I set the
contents of "myText". Why, when choosing "function" does
"&copy" show in the field instead of the copy symbol? If
there is something obviously wrong... I cannot see it.
Any comments are appreciated.

<head>
<title>My Test</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function set_it(obj)
{
obj.form.myText.value='&copy;';
}
</script>
<form action="#" method="get">
<input name="myText" type="text" value="&copy;" />
<input name="btn01" type="button" value="inline"
onClick="this.form.myText.value='&copy;';"/>
<input name="btn02" type="button" value="function"
onClick="set_it(this);"/>
</form>
</body>
</html>


You are experiencing the difference between PCDATA and CDATA. The
contents of a SCRIPT element are specified in HTML (but not XHTML) as
being CDATA; literal character data where the only significant character
sequence is ' </', which may be taken as terminating the CDATA (this is
superficial description, refer to the section of the HTML specification
on 'types' for more detail).

On the other hand the contents of the value assigned to an event
handling attribute is PCDATA and is parsed by the HTML parser. The
parser will observe entities that it recognises, such as &copy;, and
substitute them with a known character. This will happen before any code
in the even handling attribute is shown to the javascript interpreter.

As you are using the copyright symbol it may be worth mentioning that
there was a release of Netscape 6.2 (hopefully now long dead) that would
refuse to execute javascript source that contained a literal copyright
symbol).

In any event, you should be able to use a literal copyright symbol in a
string literal in CDATA, but that might not be a good idea. So instead
you should probably use a javascript escape sequence in that context:
Hex escape = \xA9 Unicode escape = \u00A9

You can also use the javascript escape sequence(s) in the event handling
attribute value, as it would mean nothing to the HTML parser.

Richard.
Nov 2 '05 #2

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

Similar topics

2
by: David Shadovitz | last post by:
I'm new to PHP and can use some help with avoiding HTML entity trouble. I've got a page which creates a hyperlink as follows: printf('<a href="%s?txtFilter=%s">%s</a>', $_SERVER, $txtFilter,...
11
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you...
1
by: Razvan | last post by:
Hi What is the difference between an internal and an external entity ? The first one is defined in the internal subset (not in a separate DTD file, but in the XML file itself - in...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
4
by: terry | last post by:
could someone tell me how to add or remove entity to a xml file when i dim xmlentity as new xmlentity it's say it's sube new is private thks
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
6
by: Tuomas Rannikko | last post by:
Hello, I'm currently writing a XML processor for the fun of it. There is something I don't understand in the spec though. I'm obviously missing something important. The spec states that both...
1
by: TAL651 | last post by:
I'm having trouble displaying entity references (i.e. >, <, etc). I'll show the code first, then ask my question. This code makes sub items on a menu appear or disappear. The HTML isn't giving me...
0
by: jagsusa | last post by:
Hi All I need to assign the current user to the people picker control in my custom ASPX page which I am planing to host in sharepoint (WSS) . I was trying on these lines but without success. ...
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...
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
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
Oralloy
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,...
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
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.