473,587 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with XHTML parsers with embedded Javascript


Hi.. I've got some code I wrote in PHP that will generate an HTML page
with embedded javascript which in turn creates a new argument
string for the browser, but the xhtml parser in Firefox and Opera both
complain about my use of &var=value pairs in the generated URL.

Below is my code that generates the string, and is part of an embedded
HTML page (generated on the fly by a PHP script):

function InvokeURL(url_t o_forward_to)
{
try
{
var xfamElem = document.getEle mentById('xFami ly');
var mainform = document.getEle mentById('mainf orm');
var new_url = url_to_forward_ to + "&variable= " + xfamElem.value;

mainform.action = new_url;
mainform.submit ();
}
catch(error)
{
alert("InvokeUR L encountered an error :" + error.descripti on);
}
}

This works fine with *many* browsers except the new ones.. With IE on
windows (IE6) and Opera, Firefox all complain, Safari and some older
browsers seem to work OK..

If I change the line with the new_url variable setting on it to use a
& instead, it passes the XHTML tests but no longer works at all.. When
using the & it still has that in the URL that shows in the address bar
and hence it seems to cause the script on the other end a lot of problems
as it is unable to properly parse the URL string.

Any ideas on how to portably get around this problem with embedded &
created URL's?

Many thanks in advance!

-- Rick

Jul 23 '05 #1
2 1565


Rick wrote:
var new_url = url_to_forward_ to + "&variable= " + xfamElem.value; This works fine with *many* browsers except the new ones.. With IE on
windows (IE6) and Opera, Firefox all complain, Safari and some older
browsers seem to work OK..


If you want to use an ampersand in XML you need to use the entity
reference & or you need to wrap your text into a CDATA section.
For script blocks in XHTML you can use e.g.

<script type="text/javascript">
//<![CDATA[
function InvokeURL(url_t o_forward_to)
{
try
{
var xfamElem = document.getEle mentById('xFami ly');
var mainform = document.getEle mentById('mainf orm');
var new_url = url_to_forward_ to + "&variable= " + xfamElem.value;

mainform.action = new_url;
mainform.submit ();
}
catch(error)
{
alert("InvokeUR L encountered an error :" + error.descripti on);
}
}
//]]>
</script>

to write your code in a way that is both compatible with HTML and XML
parsers.

If your only aim is to write X(HT)ML served to XML parsers then of course
<script type="text/javascript">
<![CDATA[
function InvokeURL(url_t o_forward_to)
{
try
{
var xfamElem = document.getEle mentById('xFami ly');
var mainform = document.getEle mentById('mainf orm');
var new_url = url_to_forward_ to + "&variable= " + xfamElem.value;

mainform.action = new_url;
mainform.submit ();
}
catch(error)
{
alert("InvokeUR L encountered an error :" + error.descripti on);
}
}
]]>
<script>

Or simply put your script code into an external .js file and include
that with

<script type="text/javascript" src="file.js"></script>

that way there will be no problems as the XML (or HTML) parser doesn't
see the script code at all.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin,

Thanks.. I'll try it out tonight! I guess I'll have to read up on these
CDATA things as it's something I wasn't aware of. I did realize that I
could have dumped this JS code into a separate file, but didn't really
want to resort to doing that unless there were no other options.

Thanks!

-- Rick
Jul 23 '05 #3

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

Similar topics

2
2107
by: Rick | last post by:
Hi.. I've got some code I wrote in PHP that will generate a new argument string for the browser, but the xhtml parser in Firefox and Opera both complain about my use of &var=value pairs. Below is my code that generates the string : function InvokeURL(url_to_forward_to) { try {
13
3656
by: Tjerk Wolterink | last post by:
Hello i've an xsl stylesheet that must support xhtml entities, my solution: ---- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE xsl:stylesheet > <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30
2258
by: Patrick | last post by:
Hello, i'm trying to get my page to XHTML 1.1 compliance, i used the validator from validator.w3.org but i still get one error message which i cant explain. Would be nice if someone can take a look on it: http://validator.w3.org/check?uri=http%3A%2F%2Fsnafu.is-a-geek.net%2Findex.html It tells me: Line 6, column 62: character data is...
2
2857
by: mike | last post by:
regards: I follow the following steps to converting from HTML to XHTML http://webpageworkshop.co.uk/main/xhtml_converting My parser is http://htmlparser.sourceforge.net/ Xhtml version is 1.0 from http://nds.nokia.com/uaprof/N6600r100.xml but nokia mobile browser cannot identify the converted file(XHTML1.0). Is there something wrong...
16
7084
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe"); MyDiv.appendChild(iframeObject); var data = "<html><head><title>testing</title></head><body>data</body></html>" iframeObject.contentDocument.open();...
82
5660
by: Buford Early | last post by:
I read this in http://annevankesteren.nl/2004/12/xhtml-notes "A common misconception is that XHTML 1.1 is the latest version of the XHTML series. And although it was released a bit more than a year later then the first version of XHTML 1.0, the second edition is actually newer. Furthermore, XHTML 1.1 is not really the follow-up of XHTML...
0
367
by: Thomas Due | last post by:
Hello, I am in the process of making my asp.net form to validate as xhtml 1.0 strict. So far I am doing well, but now I have a problem. The problem concerns specifically DropDownList and ListBox, but other controls might result in the same problem. When AutoPostBack is enabled on these controls, two hidden input fields are created on the...
11
1907
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is that in the swapcheck(x) function below, if I uncomment the first line (commented with //) the whole thing brings and IE errors the page with an...
19
1921
by: Bert Lancaster | last post by:
I'm not actually using it on the web but can anyone tell me why the ID attribute on a <style> tag causes an error in the W3C validator for an XHTML 1.1 document? It doesn't have a problem for a XHTML 1.0 or HTML document. I was just playing around with some test code that contained an embedded stylesheet and used <?xml-stylesheet...
0
8215
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, 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. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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...
0
6626
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2358
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
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.