469,275 Members | 1,287 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

IE syntax error, 80020101 and undefined array

67
Well guys,

I have tested a script that's working well in FF, however while testing with IE7, I am finding errors. That famous yellow warning icon at the left of our status bar.

Basically, I am opening a new popup window using dhtmlgoodies modal message tool. It opens well in FF, however in IE, the yellow icon appears with a bunch of erros as soon as the new window opens up.

The erros are -

1. Syntax error, line 3, character 6.
2. Could not complete the operation due to error 80020101, line 94, character 6
3. chocArray is undefined, line 71, character 1

Now here chocArray is an array I am defining in the page that opens. Strange is, when I call the page (the popup) directly using the browse, I don't see any of these errors, but when I call the page by clicking a link in the parent page, the erros come up.

I could not see anything in line 3, where the first three lines in the page (popup) reads -

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head>
Error 2, 80020101, if I have understood well by googling since the morning and by hit and trial method, is probably from error 1.

Line 71 reads (I'm giving line 57 to 72 here, space removed, so there are fewer lines here) -

<body>

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">        
  2. <!--
  3. var inter_52 = document.getElementById('chocQnty_52');
  4. if (inter_52 && inter_52.value) {
  5. var cqnty_52 = inter_52.value;
  6. } else {
  7. var cqnty_52 = 0;
  8. }                        
  9. chocArray[0] = cqnty_52 + "~" + 79;
  10. ajaxArr[0] = 52 + "~" + cqnty_52;        
  11. //-->        
  12. </script>
  13. <img src="img/spacer.gif" width="1" height="1" onload="subChoc('chocQnty_52','totale_52',79,chocArray,0,'',52,ajaxArr);" />
Any help would be highly appreciated. I am pulling out my hair since this morning 9 o'clock, and it's 7 pm now :(
Dec 18 '07 #1
14 44033
kigoobe
67
OK, it's 1 am now, and I thought to give another update with some more information, if someone can help.

I have now tested this in Safari 3, Opera 9.24, IE7 and IE6, Netscape 8.1 and 9.0.0.5, and Firefox 2.0.0.11.

Of those, the script is working only in Firefox 2.0.0.11 and Netscape 9.0.0.5 and for the rest, I am having similar bugs.

Here I am adding the full popup page (html version), just incase someone wants to have a look.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head>
  4. <title>Commande</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <script type="text/javascript" src="js/kajax.js"></script>
  7.  
  8. <script type="text/javascript">
  9. <!--
  10. var chocArray = new Array();
  11. var ajaxArr = new Array();
  12.  
  13.     function subChoc(qnty,totale,prix,chocArray,count,action,id,ajaxArr) {
  14.         chocobox = document.getElementById(qnty);
  15.         chocoPrice = document.getElementById(totale);
  16.         chocoTotal = document.getElementById('gr_totale');
  17.         if (chocobox && chocobox.value && chocoPrice && chocoPrice.innerHTML && action) {
  18.             if ( (action == 'plus') || ((action == 'minus') && (chocobox.value != 0)) || (action == '') ) {
  19.                     if (action == 'plus') {
  20.                         chocobox.value = Number(chocobox.value)+1;
  21.                     } else if (action == 'minus') {
  22.                         chocobox.value = Number(chocobox.value)-1;
  23.                     } else if (action == '') {
  24.                         chocobox.value = Number(chocobox.value);
  25.                     } 
  26.                 ajaxArr[count] = (Number(id) + "~" + chocobox.value);                
  27.                 chocoPrice.innerHTML = Number(prix) * Number(chocobox.value);
  28.                 chocArray[count] = chocobox.value + "~" + chocoPrice.innerHTML;                
  29.                 var total = 0; var price = 0;
  30.                 for(var i=0;i<chocArray.length;i++) {
  31.                     var splitMe = chocArray[i].split("~");
  32.                     if (Number(splitMe[0]) == 0) {
  33.                         price = 0;
  34.                     } else {
  35.                         price = Number(splitMe[1]);
  36.                     }
  37.                     total = Number(total) + Number(price);
  38.                 }
  39.                 chocoTotal.innerHTML = total;
  40.                 var strValue = ajaxArr.join(";");
  41.                 hidvalue = document.getElementById('quote_values');
  42.                 hidvalue.value = strValue;
  43.             } else {
  44.                 chocobox.value = chocobox.value;
  45.             }
  46.         }
  47.     }
  48.  
  49.     function resetArray() {
  50.         chocArray.length = 0;
  51.     }
  52.  
  53.  
  54. //-->
  55. </script>
  56. </head>
  57.  
  58. <body>
  59.  
  60.                     <script type="text/javascript">        
  61.                     <!--
  62.                         var inter_52 = document.getElementById('chocQnty_52');
  63.                         if (inter_52 && inter_52.value) {
  64.                             var cqnty_52 = inter_52.value;
  65.                         } else {
  66.                             var cqnty_52 = 0;
  67.                         }                        
  68.                         chocArray[0] = cqnty_52 + "~" + 79;
  69.                         ajaxArr[0] = 52 + "~" + cqnty_52;        
  70.                     //-->        
  71.                     </script>
  72.  
  73.                     <img src="img/spacer.gif" width="1" height="1" onload="subChoc('chocQnty_52','totale_52',79,chocArray,0,'',52,ajaxArr);" />
  74.  
  75. <form name="ajax" id="ajax" method="post" action="#" enctype="application/x-www-form-urlencoded">
  76.     <div class="myCommande">
  77.  
  78.         <table>
  79. <tr><th>Qté</th><th>Produits</th><th>Prix</th><th>Total</th></tr>
  80. <tr>
  81. <td class="price"><a href="#" onclick="subChoc('chocQnty_52','totale_52',79,chocArray,0,'minus',52,ajaxArr);return false;">-</a> <input type="text" id="chocQnty_52" size="1" maxlength="4" value="1" readonly="readonly" /><a href="#" onclick="subChoc('chocQnty_52','totale_52',79,chocArray,0,'plus',52,ajaxArr);return false;">+</a></td>
  82. <td>Les 365 pensées et ses 12 stylos</td>
  83. <td class="price">79 Euros</td>
  84. <td class="price"><span id="totale_52">79</span> Euros</td>
  85. </tr>
  86.  
  87. <tr><td class="t"></td><td class="t">Montant total pour <em>LES 365 PENSEES</em></td><td class="t"></td><td class="t"><span id="gr_totale">79</span> Euros</td></tr>
  88. </table>
  89.  
  90.         <input type="hidden" id="quote_values" value=";52~1;" />
  91.         <input type="hidden" id="my_cat" value="2" />
  92.         <input type="button" class="button" value="Annuler" onclick="resetArray(); closeMessage();" />
  93.         <input type="button" class="button" value="Ajouter" onclick="javascript:getAjax('getStatus.php','getStatus_2','text','quote_values','my_cat','',''); resetArray(); closeMessage();" />
  94.         </div>
  95.         <div class="break"></div>
  96.     </form>
  97. </body>
  98. </html>
  99.  
But as I told earlier, when I load this page independently using a browser (IE7 here), I don't get any error, and things seems to work. However, when I call this page from another page, I start getting all the bizzare errors.

Also, in some of the browsers like opera and netscape 8.1 it's told that the following piece of code is having syntax error.

Expand|Select|Wrap|Line Numbers
  1. function goto(page) {
  2.     if(page) {
  3.         location.href = page;
  4.     }
  5. }
  6.  
Thanks for any help guys.
Dec 18 '07 #2
kigoobe
67
OK friends, update time, just incase if someone else reaches this page googling, facing a similar situation ...

As it stands now, I have been able to debug the Safari 3 issues by removing

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head>
  4.  
from the top and the following from the bottom
Expand|Select|Wrap|Line Numbers
  1. </body>
  2. </html>
  3.  
as I found in the example code of modal message, he hasn't put these in his examples. Further, he has saved the popup page as .inc, whereas I've saved them as .php ... hope that's not another reason here.

Update 2

Removing the JS codes, taking the function to the external JS file and the array declaration to the parent page, this is now working in IE7, IE6, Safari 3 and Netscape 9. Netscape 8 is still not working, probably because I have installed Netscape 9 over netscape 8 thereby destroying some of Netscape 8's functionality, or probaby simply netscape 8 is not upto the mark. Opera is not working as well, probably this is an opera bug. Anyway, I am moderately happy if my sites work on IE6, IE7 and FF, and Safari, as I am covering most of the users that way.

If someone can point me out why this is not working, it will be good. Else, here I stop my updates, unless I found a workaround for the Opera.

Here is what Opera's error console is telling, just in case some noble soul wants to have a look.

Expand|Select|Wrap|Line Numbers
  1. JavaScript - http://www.example.com/parent.php
  2. Inline script compilation
  3. Syntax error while loading: line 180 of linked script at http://www.example.com/js/kajax.js : 
  4. function goto(page) {
  5. --------------^
  6. JavaScript - http://www.example.com/parent.php
  7. Event thread: load
  8. Error:
  9. name: ReferenceError
  10. message: Statement on line 1: Reference to undefined variable: subChoc
  11. Backtrace:
  12.   Line 1 of  script 
  13.     subChoc("chocQnty_52", "totale_52", 79, chocArray, 0, "", 52, ajaxArr);
  14.   At unknown location
  15.     [statement source code not available]
  16.  
  17. JavaScript - http://www.example.com/parent.php
  18. Event thread: click
  19. Error:
  20. name: ReferenceError
  21. message: Statement on line 1: Reference to undefined variable: subChoc
  22. Backtrace:
  23.   Line 1 of  script 
  24.     subChoc("chocQnty_52", "totale_52", 79, chocArray, 0, "plus", 52, ajaxArr);
  25. return false;
  26.   At unknown location
  27.     [statement source code not available]
  28.  
It's giving two errors, one telling that it's not finding subChoc function what's now located at kajax.js, unless this is a caching issue. And for the other function, I am unable to find out what the problem is.

Expand|Select|Wrap|Line Numbers
  1. function goto(page) {
  2.     if(page) {
  3.         location.href = page;
  4.     }
  5. }
  6.  
Dec 19 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

why do you use the img's onload? try to use the onload of the body ... even the script that directly follows the body could be started in that onload ... during page load document.getElementById() will always fail ... and return null ... after the page is loaded, it will work as expected and return the nodes properly ...

kind regards
Dec 19 '07 #4
kigoobe
67
hi ...

why do you use the img's onload? try to use the onload of the body ... even the script that directly follows the body could be started in that onload ... during page load document.getElementById() will always fail ... and return null ... after the page is loaded, it will work as expected and return the nodes properly ...

kind regards
Hmmm ... thanks Gits. Actually, I am using img onload in a few instances as variables that I'm passing on that onload are not always created at the top of the page, so I needed a way to call hte onload function at different places of a page. What's the solution then?

Thanks for your reply, btw. :)
Dec 19 '07 #5
gits
5,390 Expert Mod 4TB
... wait .. i think i don't really get it ... onload is an event that is fired when a specific node is loaded and ready to use by js-dom-methods ... the documents onload itself, that we assign to the body is the one where you have the page really and reliably ready ... i cannot think of a scenario where it couldn't be used ... and has to be replaced with other onload events?
Dec 19 '07 #6
gits
5,390 Expert Mod 4TB
as far as i know ... when you use an onload of a specific node in the document ... you cannot rely on that the document is already fully loaded ... so you don't have the dom ready to use in all cases ...
Dec 19 '07 #7
kigoobe
67
Hmmm ... you mean that whatever is the scenario, adding onload with the body tag is the best way to go ...

I've pages where I need to call a function near the end of a page, for example. What do you think would be the best way to call a function in such a scenario? I thought calling the function to an image onload event could be easiest, but as you told, that may not be the best solution. :(
Dec 19 '07 #8
gits
5,390 Expert Mod 4TB
hi ...

what do you mean with 'to call at the end of the page'? ... again: a page is loaded by the browser ... and it is parsed from top to the bottom. all ressources that are referred by a src-attrib are requested async and when everything is ready the documents onload-event is fired. so that IS semantically the 'end' of the page (its like a callback in an ajax-request ... called when the response is ready to use) ... you should always start js-processing here ... not in the html-code itself, even if you could do that ... you shouldn't :)

simply write a function that calls the things you want and call that function in the onload ...

kind regards
Dec 19 '07 #9
kigoobe
67
Hi Gits

Thanks for your reply. Sorry for the delayed reply (christmass obligations ..., was out of the town :()

Actually, by later / end of the page what I meant was, I was needing to call javascript somewhere down the page, with variables that has been achieved by now.

Consider this example -

Expand|Select|Wrap|Line Numbers
  1. <?if (isset($result)) {
  2.     $countNo = 0;
  3.     foreach ($result as $rexy) {
  4.         $cid = $rexy['user_index'];
  5.         $cprix = $rexy['prix'];
  6.         $ref = $rexy['type'];
  7.         $cat = $rexy['cat'];
  8.         ?>
  9.         <script type="text/javascript">        
  10.         <!--
  11.         var inter_<?=$cid?> = document.getElementById('chocQnty_<?=$cid?>');
  12.         if (inter_<?=$cid?> && inter_<?=$cid?>.value) {
  13.             var cqnty_<?=$cid?> = inter_<?=$cid?>.value;
  14.         } else {
  15.             var cqnty_<?=$cid?> = 0;
  16.         }                        
  17.         chocArray[<?=$countNo?>] = cqnty_<?=$cid?> + "~" + <?=$cprix?>;
  18.         ajaxArr[<?=$countNo?>] = <?=$cid?> + "~" + cqnty_<?=$cid?>;
  19.         subChoc('chocQnty_<?=$cid?>','totale_<?=$cid?>',<?=$cprix?>,chocArray,<?=$countNo?>,"",<?=$cid?>,ajaxArr);
  20.     //-->        
  21.     </script>
  22.     <?    $countNo ++;
  23. }
  24. }?>
Here I am calling javascript with variable values that I am achieving from the loop. However, here I have changed the onload event, as I have learned since then that I can call javascript functions (subChoc here) without any event actually, and directly inside a <script> tag.

I have solved most of the issues as well, following your suggestions, and moving javascript functions to an external file.

However, here is one thing. The page that holds the above code opens as popup as dhtmlgoodies's modal message tool (ajax). This page has no head / body etc, just row code with php echos to print different things in the popup.

However, though FF works properly here, IE doesn't take into account the javascript things. In fact, I can't even get an alert at the very beginning (just after <script>, not even a simple alert like alert('hi there');

If I call the popup directly from the browser, IE can read the javascript, but however, as a popup, it doesn't seem to read the javascript.

Again, if I do
Expand|Select|Wrap|Line Numbers
  1. echo '<img src="img/spacer.gif" width="1" height="1" onload="alert(\'hi again\');" />'."\r\n"; 
it works, even in IE. So it seems that I need a way to put the whole javascript thing with an event. Hmmm ...

Probably I would love to know how can I declare a javascript mixed variable, as in -
Expand|Select|Wrap|Line Numbers
  1. function onloadEvents(cid,countNo,cprix) {
  2.    var inter_+cid = document.getElementById('chocQnty_'+cid);
  3. }
Here, cid is getting a value from the function argument, and I am adding a prefix to this called inter at the beginning to get a combined variable name. Things like var 'inter_'+cid doesn't work ... Idea would be to get resulting variables like inter_36, inter_64, inter_99, etc.
Dec 25 '07 #10
gits
5,390 Expert Mod 4TB
you may try:

Expand|Select|Wrap|Line Numbers
  1. window.onload = your_init_function_reference;
  2.  
to call the function onload of the document ...

and you cannot define variables the way you did :) ... in case you need dynamically named variable-names you should use and object:

Expand|Select|Wrap|Line Numbers
  1. var obj = {};
  2. var pfx = 'inter_';
  3.  
  4. obj[pfx + cid] = 'some_value';
  5.  
now you may retrieve the value with obj.varname ...

kind regards
Dec 25 '07 #11
kigoobe
67
Hi gits

Thanks a lot for your reply. In fact, I solved this followong another tips, but this way of naming mixed variables using javascript's object is certainly new to me, and I have learned yet another new stuff, thanks to you. I really appreciate your help, and I'm sure I'm going to use this method (obj => dynamic variables) in the near future.

Thanks again for all your help :) and wish you a warm and very happy year end. Hope you had a nice xmass :)
Dec 25 '07 #12
gits
5,390 Expert Mod 4TB
glad to hear you got it working ... post back to the forum anytime you have more questions ...

kind regards
Dec 26 '07 #13
gits
5,390 Expert Mod 4TB
hi ... glad to hear that it works for you ;) ... even when i'm not a genious ... much far from it ...

post your further questions to the forum please ... because we handle different topics here and i'm going to split the last issue from this thread so that other people may find the question and answer in case they are looking for that ...

kind regards
Dec 27 '07 #14
For anybody else who runs across this particular error in IE, I generally have the issue when I try to load another javascript file within an AJAX result.

It might sound silly, but if within the results of an ajax call you have code with additional <script src="file.js"></script> calls, it will run fine on Firefox, but throw this error in IE. If you inline your javascript code it should run correctly. (IE: <script>code</script> is ok)

It's probably a good idea not to have your ajax results calling other scripts anyway. This is something that usually happens when I am in a rush to get a solution. Since I haven't seen anyone else post the solution, I thought I would mention it here.
Mar 25 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by damian birchler | last post: by
7 posts views Thread by Ray Dillinger | last post: by
12 posts views Thread by Franz Hose | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.