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_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;
mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}
//]]>
</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_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;
mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}
]]>
<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/