SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    strange Firefox issue

    I've encountered some strange problems in my years of development but I really lost on this one. Firefox is giving me this error:

    XML Parsing Error: not well-formed
    Location: https://localhost:9445/Scheduler3/
    Line Number 189, Column 36: for ( i= (len - 1); i >= 0; i--) {
    ---------------------------------------------------------------^

    Normally if I got an XML parse error I can fix it quite easily, except for some reason firefox tries to parse Javascript as XML.

    The script has a <!-- at the beginning so it should ignore this. Now it gets even stranger because I can do a "view source", copy and paste this into another file and then Firefox loads it up just fine. The page is dynamically generated.

    Now I've got the problem down to this function, removing it will let the page load, but I need the function:

    Code:
     
     function submitDate(date) {
     		
     			var selectBox = document.form.date;
     			if (date != null) {
     				/* clear elements */
     				var len = selectBox.length;
     				for ( i= (len - 1); i >= 0; i--) {
     					selectBox.options[i] = null;
     				}	
     				/* add the new element */
     				selectBox.options[0] = new Option (date, date);
     				/* synchronize the javascript calendar's offset */			
     				var lowerDate = strToDate('2006-08-14'); // strToDate() defined in calendar.js
     				var upperDate = strToDate(date);
     				var swapped = false;
     				var count = 0;
     	
     				if (lowerDate > upperDate) { // swap
     					var temp = lowerDate;
     					lowerDate = upperDate;
     					upperDate = temp;
     					swapped = true;
     				}
     	
     				while (lowerDate < upperDate) {
     					count++;
     					lowerDate.setMonth(lowerDate.getMonth() + 1);
     				}
     
     				document.form.offset.value = (swapped ? (count - 1) * -1 : count);
     			}
     			selectDates();
     			document.form.submit();
    }
    Any idea why this function would cause a problem? It works fine in IE, and in Firefox if I copy and paste it into another file, for that matter, I've used this same function elsewhere and it works fine (hence my general confusion on the issue).

    Thanks

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript should generally be cited in the form:

    HTML Code:
    <script type="text/javascript">
    <![CDATA[
    Script here
    ]]>
    </script>
    The CDATA part is there to make sure the contents are not parsed as XML. I think that's your problem, being that it's thinking the > is ending an xml tag.

  3. #3
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so I guess <!-- is deprecated, I never thought to use the CDATA thing, although I guess since this is XHTML now that makes sense. This fixed the problem. Thanks.

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may wish to read this regarding CDATA, JavaScript and legacy browsers. Most would agree that the ideal is to simply use an external script file.

    http://developer.mozilla.org/en/docs...ad_of_Comments

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    <!-- --> is for entering comment text. Comments will be parsed unless they are inside a CDATA tag and so may not contain > characters. Also the content of a comment may be completely ignored resulting in your script not running because it is considered to be commented out. The prectice of commenting out scripts to hide them from version one browsers that didn't understand Javascript became completely unnecessary by the time everyone was using Netscape 2 or IE3 or better.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •