views:

72

answers:

2

Dear all,

I have some trouble as simple as debugging a for loop or a while loop. Do you have any clue? a function that returns data without any iteration works fine but not the loop.

<script language = "javascript">
        function h(arr)
    {
    <![CDATA[

        var ref = arr[0];

        i = 0
        while(i<arr.length){
            if(arr[i]!= arr[0])
            {
                return 1
            }
            i++;
        }
        return 0

    ]]>
    }

I need it for the XSL not to confuse the < with the tag but consider it as a comparison operator. HELP

A: 

what is <![CDATA[ doing inside your code?

akonsu
I need it for the XSL not to confuse the < with the tag but consider it as a comparison operator.
Atlas
This should be a comment.
Pekka
+1  A: 

Try correcting the following:

The CData tags will want to go outside the function (immediately below and above the open and close script tags respectively). These are only really needed if you are validating your HTML: http://javascript.about.com/library/blxhtml.htm

<script>
<![CDATA[
     // content of your Javascript goes here
]]>
</script>

Add semi-colons on i=0 and return 0 lines.

Use !== instead of != this will do a type comparison as well.

Give us some more info. Its hard to tell

James Wiseman