substitute a variable with a string

J

jrough

I have a question why doesn't this script substitute out for the alert
line in the xmltostring function.
I don't get an alert or substitution from the a= {b}. Thanks


<html>
<body>
<script type = "text/javascript">
var b= 'Best of luck "Studentname & Roll no" for your exam';
var el = '<foo a={b}/>';
alert(el.toXMLString());
</script>
</body>
</html>
 
J

jrough

Assumptions are dangerous :)
I assumed E4X was Javascript and I could access it in my browser using
my web server.
That sounds like it was wrong. Do you mean I need a different doctype
for Javascript with XML or something like that?
If you have a web page I can read about this that would help.
I thought EcmaJS whatever was the overall standard and Javscript was
a flavor of it that pretty
much followed that standard so I don't know how you mean to implement
it or how you even know it is EcmajS
but it does make sense that I need an xml
file or something for this to work.
 
R

RobG

Assumptions are dangerous :)

Please don't top-post, reply below trimmed quotes. Don't quote
signatures or anything below them.
I assumed E4X was Javascript and I could access it in my browser using
my web server.

Strictly, JavaScript is a trade mark of whoever bought it from Sun
(probably Oracle I guess). It is the implementation of ECMAScript
(ECMA-262), DOM APIs etc. in Netscape and Mozilla browsers.

E4X is an extension to ECMAScript and is defined in ECMA-357. So a
JavaScript (or any other implementation of ECMAScript) could include
ECMA-357 if it wished. It has been implemented in Spidermonkey, which
is the script engine in Firefox, but not made fully available by
default (perhaps only for HTML documents).

That sounds like it was wrong.
Perhaps.

 Do you mean I need a different doctype
for Javascript with XML or something like that?

It is intended to be used with XML documents, which should be valid in
regard to their XML document declaration and DOCTYPE (if included).

But you may be able to use it in HTML documents, according to the
Mozilla E4X documentation:

| In Gecko 1.8 based browsers such as Firefox 1.5,
| E4X is already partially enabled for web page
| authors. To fully enable E4X, the <script> element
| needs to have the MIME type "text/javascript;e4x=1"

If you have a web page I can read about this that would help.
I thought EcmaJS whatever  was the overall standard and Javscript was
a flavor of it that pretty

The language is ECMAScript, the standard is ECMA-262, the current
edition is edition 5.

<URL: http://www.ecma-international.org/publications/standards/Ecma-262.htm
JavaScript is one implementation of ECMAScript, there are many others.
The word "javascript" or "Javascript" or "JavaScript" is often used to
generically describe ECMAScript-based scripting environments used in
web browsers and other hosts.

much followed that standard so I don't know how you mean to implement
it or how you even know it is EcmajS
but it does make sense that I need an xml
file or something for this to work.

You could start with w3schools[1] but beware: much of what you learn
there will not be strictly correct (sometimes plain wrong) but it will
get you going. More authoritative but perhaps a bit harder to get
going with is the Mozilla E4X documentation linked to above. Judging
by the similarity between the tutorial and your posted code you may
have already discovered it.

1. <URL: http://www.w3schools.com/e4x/default.asp >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top