473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(str)
{
var obj=document.getElementById("myDiv");

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="ChangeContent(this.value)" />
<br />
Display2 <input type="radio" name="States" value="display2"
onchange="ChangeContent(this.value)" />

<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 37986
ASM
John a écrit :

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

<script type="text/javascript">
function ChangeContent(str)
{
var obj=document.getElementById("myDiv");
if(str.selected)
obj.innerHTML = (str.value=="display1")?
"<b>display 1 was selected<\/b>" :
(str.value=="display2")?
"<b>display 2 was selected<\/b>" :
"";
}
</script>

</head>

<body>
<form>
Display1 <input type="radio" name="States" value="display1"
onclick="ChangeContent(this)" />
<br />
Display2 <input type="radio" name="States" value="display2"
onclick="ChangeContent(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.getElementById(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....@gmail.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(str)
{
var obj=document.getElementById("myDiv");

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="ChangeContent(this.value)" />
<br />
Display2 <input type="radio" name="States" value="display2"
onchange="ChangeContent(this.value)" />

<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(str)
{
var obj=document.getElementById("myDiv");

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(str)
{
var obj=document.getElementById("myDiv");

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.getElementByID("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.getElementByID) { //Open standards method
var obj=document.getElementById("myDiv");
}
else if(document.all) { //IE method
var obj=document.all['myDiv']; //Note the brackets rather than
parenthesis
}

Feb 26 '07 #6
VK
On Jan 13, 8:36 pm, "John" <quanza....@gmail.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(str)
{
var obj=document.getElementById("myDiv");

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="ChangeContent(this.value)" />
<br />
Display2 <input type="radio" name="States" value="display2"
onchange="ChangeContent(this.value)" />

<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**********@gmail.com wrote:
The reason this code works in Firefox and not IE is due to your
calling of document.getElementByID("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
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...
6
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...
0
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...
2
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...
2
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...
2
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...
4
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...
7
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"> ...
1
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...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.