473,574 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript IE problem "unknown runtime error" when using innerHTML

Hi Everyone,

I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement using innerHTML.

Now, I've researched this problem on the web, and found many references
to it, but none of them quite addressed my specific situation, and
since my experience with JavaScript is limited, I was not able to adapt
the solutions I found to my specific situation.

Anyway, it's all very basic:

I have a <div id="myDiv"></divelement that's inside a <form></form>
element. I'm trying to change the innerHTML of the <divelement when
clicking on a "radio" button.

This code works fine in Firefox:

<html>
<head>
<title>My Page</title>

<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");

if (str=="display1 ")
{
obj.innerHTML = "<b>display 1 was selected</b>";
}
else if (str=="display2 ")
{
obj.innerHTML = "<b>display 2 was selected</b>";
}
}
</script>

</head>

<body>
<form>
Display1 <input type="radio" name="States" value="display1 "
onchange="Chang eContent(this.v alue)" />
<br />
Display2 <input type="radio" name="States" value="display2 "
onchange="Chang eContent(this.v alue)" />

<div id="myDiv"></div>
</form>
</body>

</html>

As I said, it works perfectly in Firefox, but in IE6 I get the error:
"unknown runtime error"
>From what I could gather on the web, this is probably some kind of a
"parent" "child" problem, since the <divelement is inside of a form..
however since as I've mentioned my experience with JavaScript is
limited, I need a practical example of how I can solve this issue for
my particular situation...

Any help will be greatly appreciated!!!! !

Jan 13 '07 #1
7 37999
ASM
John a écrit :

I haven't IE, but you could try :
<html>
<head>
<title>My Page</title>

<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");
if(str.selected )
obj.innerHTML = (str.value=="di splay1")?
"<b>display 1 was selected<\/b>" :
(str.value=="di splay2")?
"<b>display 2 was selected<\/b>" :
"";
}
</script>

</head>

<body>
<form>
Display1 <input type="radio" name="States" value="display1 "
onclick="Change Content(this)" />
<br />
Display2 <input type="radio" name="States" value="display2 "
onclick="Change Content(this)" />

<div id="myDiv"></div>
</form>
</body>

</html>

As I said, it works perfectly in Firefox, but in IE6 I get the error:
"unknown runtime error"
Probably because you didn't escape / of </bin your innerHTML ?
>>From what I could gather on the web, this is probably some kind of a
"parent" "child" problem, since the <divelement is inside of a form.
I hope it is not that.

On my idea it is curious to use onchange about a radio-button or a
checkbox where no content can change ...
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 14 '07 #2
with my ie i don't get any error message.
i am using ie6, too. i haven't apply the sp yet.
sk
Jan 14 '07 #3
dd
I've been programming JS and primarily testing it first on IE6 for
years
and have never seen an "unknown runtime error". Have you tried it on
other machines?

I have a suggestion for you though. You're not checking whether
the obj exists after your getElementById. It's always good practice
to do this construct:

var obj=document.ge tElementById(id );
if(obj){
//do stuff with obj
}

During testing you could have it alert that the object doesn't exist.

else alert("obj didn't exist with id=="+id);

Perhaps that's part of your problem, perhaps not. You'd normally
see an error that it doesn't exist, rather than an unknown runtime
error. Considering I've never seen such a thing though, I thought
I'd bring this to your attention. You never know.

Jan 16 '07 #4
On Jan 13, 6:36 pm, "John" <quanza....@gma il.comwrote:
Hi Everyone,

I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement using innerHTML.

Now, I've researched this problem on the web, and found many references
to it, but none of them quite addressed my specific situation, and
since my experience with JavaScript is limited, I was not able to adapt
the solutions I found to my specific situation.

Anyway, it's all very basic:

I have a <div id="myDiv"></divelement that's inside a <form></form>
element. I'm trying to change the innerHTML of the <divelement when
clicking on a "radio" button.

This code works fine in Firefox:

<html>
<head>
<title>My Page</title>

<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");

if (str=="display1 ")
{
obj.innerHTML = "<b>display 1 was selected</b>";
}
else if (str=="display2 ")
{
obj.innerHTML = "<b>display 2 was selected</b>";
}}

</script>

</head>

<body>

<form>
Display1 <input type="radio" name="States" value="display1 "
onchange="Chang eContent(this.v alue)" />
<br />
Display2 <input type="radio" name="States" value="display2 "
onchange="Chang eContent(this.v alue)" />

<div id="myDiv"></div>
</form>

</body>

</html>

As I said, it works perfectly in Firefox, but in IE6 I get the error:
"unknown runtime error"
From what I could gather on the web, this is probably some kind of a

"parent" "child" problem, since the <divelement is inside of a form..
however since as I've mentioned my experience with JavaScript is
limited, I need a practical example of how I can solve this issue for
my particular situation...

Any help will be greatly appreciated!!!! !

you had to try with a simple javascript string like "ok" or "not ok"
and your code should work but with html tags just need to escape / in
javascript strings !!!

your code modified :

<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");

if (str=="display1 ")
{
obj.innerHTML = "<b>display 1 was selected<\/b>";
}
else if (str=="display2 ")
{
obj.innerHTML = "<b>display 2 was selected<\/b>";
}
}

</script>

Feb 7 '07 #5
This code works fine in Firefox:
<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");

if (str=="display1 ")
{
obj.innerHTML = "<b>display 1 was selected</b>";
}
else if (str=="display2 ")
{
obj.innerHTML = "<b>display 2 was selected</b>";
}}

</script>
The reason this code works in Firefox and not IE is due to your
calling of document.getEle mentByID("myDiv "); This method is the open
standards way of pulling objects in the DOM, but IE does not follow
this rule. Adding this check should allow it to work for both IE and
Firefox:

if(document.get ElementByID) { //Open standards method
var obj=document.ge tElementById("m yDiv");
}
else if(document.all ) { //IE method
var obj=document.al l['myDiv']; //Note the brackets rather than
parenthesis
}

Feb 26 '07 #6
VK
On Jan 13, 8:36 pm, "John" <quanza....@gma il.comwrote:
Hi Everyone,

I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement using innerHTML.

Now, I've researched this problem on the web, and found many references
to it, but none of them quite addressed my specific situation, and
since my experience with JavaScript is limited, I was not able to adapt
the solutions I found to my specific situation.

Anyway, it's all very basic:

I have a <div id="myDiv"></divelement that's inside a <form></form>
element. I'm trying to change the innerHTML of the <divelement when
clicking on a "radio" button.

This code works fine in Firefox:

<html>
<head>
<title>My Page</title>

<script type="text/javascript">
function ChangeContent(s tr)
{
var obj=document.ge tElementById("m yDiv");

if (str=="display1 ")
{
obj.innerHTML = "<b>display 1 was selected</b>";
}
else if (str=="display2 ")
{
obj.innerHTML = "<b>display 2 was selected</b>";
}}

</script>

</head>

<body>

<form>
Display1 <input type="radio" name="States" value="display1 "
onchange="Chang eContent(this.v alue)" />
<br />
Display2 <input type="radio" name="States" value="display2 "
onchange="Chang eContent(this.v alue)" />

<div id="myDiv"></div>
</form>

</body>

</html>

As I said, it works perfectly in Firefox, but in IE6 I get the error:
"unknown runtime error"
Yeah. And the googled coverage is rather amazing:
<http://www.google.com/search?hl=en&q...error+Internet
+Explorer&btnG= Google+Search>
So many different explanations (some are stated as the ultimate truth
atop of it) and not a single correct one.

The problem is that the code you have posted is not the code you have
troubles with. The actual code would look something like here <http://
piecesofrakesh. blogspot.com/2007/02/ies-unknown-runtime-error-when-
using.html>

Try to notice the principal difference. If no luck then it is time to
learn the "VK's mantra" I'm too lazy to search a post, easier to type
in as it's very short and simple:

Before page load event document.write only
Ohmmm...
After page load event DOM methods only
Ohmmm...

;-)

Feb 26 '07 #7
ma**********@gm ail.com wrote:
The reason this code works in Firefox and not IE is due to your
calling of document.getEle mentByID("myDiv "); This method is the open
standards way of pulling objects in the DOM, but IE does not follow
this rule.
Rubbish. Of course IE supports getElementById.
Feb 26 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1234
by: Fresh Air Rider | last post by:
Could anyone please explain why it causes a JavaScript error when I simply add an <asp:LinkButton> to a User Control and then reference and tag that user control within a webform ? I am using Visual Studio .Net 2003 an C# I have found postings from other programmers experiencing the same problem but no-one has put forward a solution. ...
6
1573
by: Richard Silverstein | last post by:
I'm a member of a forum sponsored by jasc.com ( http://forums.jasc.com/ ) which uses Webboard software. I use Firefox 1.0 (final release) as my browser. When I used previous versions of FF I had no problem logging into the forum. But with v. 1.0 I'm getting a javascript error saying "You could not be logged in." When I login from IE I...
0
1341
by: Jéjé | last post by:
Hi, I receive this javascript error when I switch the asyncrendering option to false: oReportDiv is undefined. when I inspect the HTML content of my page, I found that a function call the oreportdiv object instead-of the clientID of the reportviewer object. (ctl00_ContentPlaceHolder1_ReportViewer1oReportDiv in my case) so the call fail.
2
1469
by: Ben Fidge | last post by:
Hi I'm getting javascript errors when I use Validator controls on my checkout page which runs under SSL. This is only happening on Windows 2003 server though and not on my XP development machine. The JavaScript error itself is not revealing much and therefore doesn't give any real indication to where the error is. The error itself just...
2
2221
by: Onur | last post by:
Hi, I have placed a <asp:menu> control inside a master page and used a style sheet to change the appearance of the menu items when the user hovers over them. My problem is the submenus aren't poping out and the page displays a javascript error saying "Object Expected". The funny thing it works on my pc but not when I migrate it to the...
2
2752
by: Diffident | last post by:
Hello All, ASP.NET 1.1 and Visual Studio 2003. I have a page which has few datagrids, validation controls and other server controls. When the page is rendered in the browser I am seeing a javascript error at the very bottom of the page. I am not using any custom javascript code except for what is inherently generated by .NET framework. ...
4
3088
by: Phil | last post by:
Hi, This code gives an javascript error: "Object required" and never let see the Alert window. in code-behind: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Hiddenfield1.value="end text" end sub
7
3080
by: preeti13 | last post by:
i have a java script function with the pop up i want to update a database ow i am getting the erorr any one please help me with this. code is like this <script type="text/javascript"> function disp_confirm(employeenominationid) {
1
1336
by: sarath chandran | last post by:
Hi all, I am using a mozilla browser and the below piece of code appears to be erroneous.It works well with Internet explorer. Here I am getting the session id and storing it ina variable. How will I do this when I chnage to Mozilla Browser? var sessID = window.parent.parent.loginFrame.getSessionID();
1
3133
by: aloksingh83 | last post by:
This error coming when i am using telerik grid.It works fine in asp.net grid what i am trying to do is taking values from textbox and show in grid view... here is the code: <script language="javascript" type="text/javascript"> function AddItems() { var lgrd = document.getElementById('<%=RadGrid1.ClientID%>'); ...
0
7828
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
7742
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
8089
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
8127
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
6493
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...
1
5638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3783
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2257
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1362
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.