473,583 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE JScript Runtime Error "Object Expected"

RMWChaos
137 New Member
WinVista/IE7

I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is:

"A Runtime Error has occurred."
"Line:xxx"
"Error: Object expected"

and Debug says: "Microsoft JScript runtime error: Object expected."

The line in my code that debug points to is:

Expand|Select|Wrap|Line Numbers
  1. loadDiv("divlogin");
  2.  
I guess there is something fundamentally different between how JScript and Javascript behave (duh!), but I just cannot figure out what is wrong.

The code is relatively simple. "loadDiv(id )" simply creates a 'div' element in 'document.body' with an id, as you would expect, of object "id". What could be simpler? But to be sure, here is my loadDiv() code:

Expand|Select|Wrap|Line Numbers
  1. function loadDiv(id)
  2.  
  3.     {
  4.  
  5.     var elemDiv = document.createElement('div');
  6.  
  7.     elemDiv.id = id;
  8.  
  9.     document.body.appendChild(elemDiv);
  10.  
  11.     };
  12.  
Like I said, very simple. Perhaps I need to do this a different way. Does IE prefer the code like this instead:

Expand|Select|Wrap|Line Numbers
  1. function loadDiv(id)
  2.  
  3.     {
  4.  
  5.     var elemDiv = document.createElement('div');
  6.  
  7.     elemDiv.setAttribute("id", id);
  8.  
  9.     document.body.appendchild(elemDiv);
  10.  
  11.     };
  12.  
Is one way better than another?

Thanks.
Oct 23 '07 #1
10 13295
Logician
210 New Member
WinVista/IE7

I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is:

"A Runtime Error has occurred."
"Line:xxx"
"Error: Object expected"

and Debug says: "Microsoft JScript runtime error: Object expected."

The line in my code that debug points to is:

Expand|Select|Wrap|Line Numbers
  1. loadDiv("divlogin");
  2.  
If that is definitely the line, then it can only mean that the function is undefined. Are you sure there's nothing in the Firefox console?
Oct 24 '07 #2
Ferris
101 New Member
hi

I have test your function "loadDiv" in firefox and IE7, it's fine.

I think the problem is "loadDiv("divlo gin");". the browser can't find loadDiv funcion.I think you need to provide more code.

by the way,I guess there should have an error in firefox.firefox will not alert an error message,and the error message will be saved in "Error Console".you can check it in "tool"->"Error Console".
Oct 24 '07 #3
RMWChaos
137 New Member
I've been running Firebug. No errors reported in FF at all. But I think I know what the problem is.

I am using addEvent to initiate my external scripts including my loadDOM.js script, which has my loadDiv() function in it, and any function called by addEvent too soon doesn't find it defined. If I wait and run loadDiv say with an onclick="" attrib, it works. So this is a timing issue...I'm firing off loadDiv() commands too soon.

So I suppose I need to add a conditional if(loadDiv) or put my loadDOM code into my loadInit.js file rather than call it from addEvent. Dunno, have to consider this a bit.

Thanks for your replies!
Oct 24 '07 #4
Ferris
101 New Member
hi

I don't think you need to change the code in loadDiv because you didn't recieve any error message in Firefox.I guess maybe you used "addActionListe ner" to add an event to your button. or maybe you can just move your functions in the right position.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.     function  loadDiv....
  5.     function  load2....
  6. </head>
  7.  
  8. <body>
  9.     <input type = "button" id="btn" .../>
  10. </body>
  11.  
  12.     function addEvent()
  13.     {
  14.         loadDiv();
  15.         load2();
  16.         ....
  17.     }
  18.  
  19.     document.getElementById("btn").onclick = addEvent;
  20. <html>
  21.  


hope it helps.
Oct 24 '07 #5
RMWChaos
137 New Member
Thanks Ferris, and yes, addEvent() does use addEventListene rs, but I don't load any code in my HTML except a link in HEAD to my loadInit.js file. Additionally, all my scripts are broken up into different files in order to reduce bandwidth needs and speed up response time (on-demand javascripts). So really, my problem is much more complicated than I made it out to be. Here's the basic structure of my site:

Single webpage:

HTML calls loadInit.js file, which contains addEvent() functions.

loadInit.js calls all my other scripts using addEvent() for onload, onunload, etc.

Some of my scripts are:

loadDOM.js - contains all my DOM element creation and removal functions.

loadXHR.js - contains my XMLHttpRequest functions.

loadLogin.js - contains my login verification and processing functions. This is where my problem is at the moment.

So either my loadDOM functions are not being loaded into the global space where my other functions can access them, or my other functions like those in loadLogin are loading too quicky / too early before loadDOM is loaded. I am working on testing this now by manually initiating loadLogin with an onclick="" after the page loads (loadDOM runs at window onload at the moment).

I don't know if my addEvent functions initiate in the order they are listed. I need to research that. It's not my code.

I should add that my addEvent function does far more than just control the adding of events. It controls the the browser cache as well to address memory leaks in IE through a removeEvent function and an EventCache function. I can always post the script here if you are interested in seeing it. It's called "Rock Solid addEvent()".

Because addEvent does more than just load up scripts after the page has loaded, I don't know how it affects the loading of functions and vars into global space.
Oct 24 '07 #6
Ferris
101 New Member
Hi

it sounds complicated..

but if the addEventListene r remain in your code,your code will never be correct in IE,because addEventListene r is only supported in Firefox,not in IE.


you can try to change addEventListene r into some other code,for example

document.getEle mentById("btn_o k").addEventLis tener('click',f unc,false);
->
document.getEle mentById("btn_o k").onclick=fun c;


if the error still exsist, it is really complicated..

hope it helps. :)
Oct 24 '07 #7
RMWChaos
137 New Member
At the moment, I have stopped using Add Event until I get all my independent scripts working, which I almost have. Once I do that, I will reintroduce Add Event.

In the meantime, here's the first part of the Add Event script, which doesn't include the removeEvent() or EventCache() functions. As you can see, the code forks depending on the browser's capabilities:

Expand|Select|Wrap|Line Numbers
  1. function addEvent(obj, type, fn)
  2.  
  3.     {
  4.  
  5.     if (obj.addEventListener) // FireFox, NN, Mozilla, etc.
  6.  
  7.         {
  8.  
  9.         obj.addEventListener(type, fn, false);
  10.  
  11.         // bugzilla bug #241518
  12.  
  13.         EventCache.add(obj, type, fn);
  14.  
  15.         }
  16.  
  17.     else if (obj.attachEvent) // MSIE
  18.  
  19.         {
  20.  
  21.         var func = function()
  22.  
  23.             {
  24.  
  25.             fn.apply(window.event.srcElement);
  26.  
  27.             };
  28.  
  29.         obj.attachEvent("on" + type, func);
  30.  
  31.         EventCache.add(obj, type, func);
  32.  
  33.         }
  34.  
  35.     else if (typeof obj['on' + type] != 'function')
  36.  
  37.         {
  38.  
  39.         obj['on' + type] = fn;
  40.  
  41.         }
  42.  
  43.     else // really old
  44.  
  45.         {
  46.  
  47.         var oldonload = obj['on' + type];
  48.  
  49.         obj['on' + type] = function()
  50.  
  51.             {
  52.  
  53.             oldonload();
  54.  
  55.             fn();
  56.  
  57.             };
  58.  
  59.         };
  60.  
  61.     };
  62.  
Oct 24 '07 #8
RMWChaos
137 New Member
And just in case anyone is interested (for you code junkies out there who get all excited just over the chance at looking over code), here is the rest of the Rock Solid addEvent() script:

By the way, a question: can anyone explain to me the reason for the ' (); ' at the very end? You can read more about the original code on Mark Wubben's Site.

Expand|Select|Wrap|Line Numbers
  1. function removeEvent(obj, type, fn)
  2.  
  3.     {
  4.  
  5.     EventCache.remove(obj, type, fn);
  6.  
  7.     };
  8.  
  9.  
  10. var EventCache = function()
  11.  
  12.     {
  13.  
  14.     var listEvents = [];
  15.  
  16.     return {
  17.  
  18.         listEvents : listEvents,
  19.  
  20.         add : function(node, sEventName, fHandler)
  21.  
  22.             {
  23.  
  24.             listEvents.push(arguments);
  25.  
  26.             },
  27.  
  28.         remove : function(node, sEventName, fHandler)
  29.  
  30.             {
  31.  
  32.             var i, item;
  33.  
  34.             for(i = listEvents.length - 1; i >= 0; i = i - 1)
  35.  
  36.                 {
  37.  
  38.                 if(node == listEvents[i][0] && sEventName == listEvents[i][1] && fHandler == listEvents[i][2])
  39.  
  40.                     {
  41.  
  42.                     item = listEvents[i];
  43.  
  44.                     if(item[0].removeEventListener)
  45.  
  46.                         {
  47.  
  48.                         item[0].removeEventListener(item[1], item[2], item[3]);
  49.  
  50.                         };
  51.  
  52.                     if(item[1].substring(0, 2) != "on")
  53.  
  54.                         {
  55.  
  56.                         item[1] = "on" + item[1];
  57.  
  58.                         };
  59.  
  60.                     if(item[0].detachEvent)
  61.  
  62.                         {
  63.  
  64.                         item[0].detachEvent(item[1], item[0][sEventName+fHandler]);
  65.  
  66.                         };
  67.  
  68.                     item[0][item[1]] = null;
  69.  
  70.                     };
  71.  
  72.                 };
  73.  
  74.             },
  75.  
  76.         flush : function()
  77.  
  78.             {
  79.  
  80.             var i, item;
  81.  
  82.             for(i = listEvents.length - 1; i >= 0; i = i - 1)
  83.  
  84.                 {
  85.  
  86.                 item = listEvents[i];
  87.  
  88.                 if(item[0].removeEventListener)
  89.  
  90.                     {
  91.  
  92.                     item[0].removeEventListener(item[1], item[2], item[3]);
  93.  
  94.                     };
  95.  
  96.                 if(item[1].substring(0, 2) != "on")
  97.  
  98.                     {
  99.  
  100.                     item[1] = "on" + item[1];
  101.  
  102.                     };
  103.  
  104.                 if(item[0].detachEvent)
  105.  
  106.                     {
  107.  
  108.                     item[0].detachEvent(item[1], item[2]);
  109.  
  110.                     };
  111.  
  112.                 item[0][item[1]] = null;
  113.  
  114.                 };
  115.  
  116.             }
  117.  
  118.         };
  119.  
  120.     }();
  121.  
Oct 24 '07 #9
Ferris
101 New Member
Hi

I think there's no problem in your event code...
Oct 25 '07 #10

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

Similar topics

4
47617
by: Danny | last post by:
Hi I don't understand why I keep getting "Error: Object expected" I tried different things and haven't been able to solve it. I'm a newbie so I'm not sure what I'm doing wrong. The debugger breaks at the <BODY> Tag of my code so I'm thinking the problem is with my InitPage() function. I appreciate the advice. Here is my code. <SCRIPT...
5
19026
by: theroo | last post by:
Hi there, I am driving myself crazy over this problem. I have used this very same function in another page without any problems, but now I am experiencing the "Error: Expected ';'" when i try and run it, and it doesn't fire (obviously, because there is an error). The code is:
1
6620
by: STAGED | last post by:
The script: proc bugsy { } { global helmet pack forget .widget1 if { $helmet(key1) } { pack .widget2 -anchor nw -side top -expand 0 } else { show_new_widget }
16
47674
by: Steve Chapel | last post by:
When I load the page <https://bugzilla.mozilla.org/attachment.cgi?id=237739with Internet Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I click on the button, I also get the same error on line 186. This same HTML and JavaScript works perfectly in Firefox and Opera. How can I make the code work in IE?
1
2143
by: monudjn | last post by:
Hi I am implementing ajax in portal. Using ajax i am able to updating the content of portlets asynchronously. However i am facing a problem The Problem: While submitting the form i am getting javascript error " Object expected". These errors i am getting after implementing ajax. Also this error is shown only the first time i trying to submit....
6
5315
by: Lawrence Spector | last post by:
I ran into a problem using g++. Visual Studio 2005 never complained about this, but with g++ I ran into this error. I can't figure out if I've done something wrong or if this is a compiler bug. Here's a very simple example which should illustrate what I'm doing. #include <iostream> template <class T> class TestBase {
5
2856
by: Diego Ruiz | last post by:
Hi!! my english is not too good, but i'll try it I have a javascript code: function executeCommands(inputparms) { // Instantiate the Shell object and invoke its execute method. var oShell = new ActiveXObject("Shell32.Application");
2
5718
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%= ViewData %>" /> -
9
11175
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list even then I should be able to get correct value for the array element. I need value and state to be present in a single byte thats why I use macros. ...
0
7895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5374
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3818
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.