I reckon using a separate .js file is the way to go - I especially
appreciate the {' '} hint.  

Thanks,

Tim

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Eric
Palmitesta
Sent: Friday, January 30, 2009 11:12 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] embedded javascript problem converting<
to &lt; even though I'm using a CDATA section

I ran into similar problems with in-script and in-line javascript in 
xquery pages, but all problems were mitigated by relocating all JS code 
to *.js files and referencing them via <script type="text/javascript" 
src="file.js">{' '}</script>, leaving only simple JS function calls in 
my xquery code.

The {' '} is there between the script tags to prevent marklogic from 
collapsing them into <script ... />.

Eric

Tim Meagher wrote:
> I have trying to embed some javascript in an xquery file and am enclosing
> the script in a CDATA section, but when the page renders, the less than
> operator
> 
>       <
> 
> is getting converted to
> 
>       &lt;
> 
> which renders the javascript useless.  Here's the javascript code (note
the
> less than comparator used in for loop of the clearForm function) embedded
in
> the head element:
> 
> ---------------------------------------------------------
> 
>  <head><title>blah blah blah</title>
>     <script type="text/javascript">
>         <![CDATA[
>         var foo = function() { alert('test') };
> 
>         function clearForm(oForm) {
>             var elements = oForm.elements; 
>             oForm.reset();
>             for(i=0; i<elements.length; i++) {
>                 field_type = elements[i].type.toLowerCase();
>                 switch(field_type) {
>                     case "text": 
>                     case "password": 
>                     case "textarea":
>                     case "hidden":
>                         elements[i].value = ""; 
>                         break;
>                     case "radio":
>                     case "checkbox":
>                         if (elements[i].checked) {
>                             elements[i].checked = false; 
>                         }
>                         break;
>                     case "select-one":
>                     case "select-multi":
>                         elements[i].selectedIndex = -1;
>                         break;
>                     default: 
>                         break;
>                 }
>             }
>         }
>         ]]>
>     </script>
> </head>
> 
> ---------------------------------------------------------
> 
> - Tim
> 
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to