473,405 Members | 2,154 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,405 software developers and data experts.

DOM innerHTML "runtime error" in IE 6

Hi,

The error I am describing occurs with the script I've pasted below.

It's a validator for form fields and prints a message into a span tag located beside the empty input tag.

I have hard coded the error message to be printed in a specific span tag for testing. --> "<span id="name">www</span>"

When this span tag is positioned BEFORE the input tag it works fine but when I place it after (which is the layout I want) it stops working and gives a "runtime error" message.

Any ideas what is causing this?

Any help would be greatly appreciated.
Thanks in advance, Will



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.  
  5.         <script type="text/javascript">
  6.  
  7.             function validate_form()
  8.             {    
  9.  
  10.                 var x;
  11.                 for (i=0; i<document.registerForm.elements.length; i++)
  12.                 {
  13.                      x = document.registerForm.elements[i];
  14.  
  15.                     if (x.type != "button" && x.type != "submit" && x.type != "hidden" && x.value == "")
  16.                     {
  17.                         //var fieldName = x.name;
  18.                         var obj=document.getElementById('name');
  19.                         if(obj){
  20.                          alert("found");
  21.                         }
  22.  
  23.                         obj.innerHTML = "Visit W3Schools";
  24.  
  25.                         alert("false");        
  26.                     }
  27.  
  28.                 }
  29.  
  30.                 alert("true");    
  31.  
  32.             }
  33.         </script>
  34.     </head>
  35.     <body>
  36.  
  37.                 <form name="registerForm"  >
  38.  
  39.                     <table>
  40.  
  41.                     <tr><td>Name:</td><td>   <input name="name" type="text" size="35" />   <span id="name">www</span> </td></tr>
  42.  
  43.  
  44.                     <tr><td>Age:</td><td><input name="age" type="text" size="35" /><span id="age"></span></td></tr>
  45.  
  46.  
  47.                     <tr><td>Phone:</td><td><input name="phone" type="text" size="35" /><span id="phone"></span></td></tr>
  48.  
  49.  
  50.                     <tr><td>Email:</td><td><input name="email" type="text" size="35" /><span id="email"></span></td></tr>
  51.  
  52.  
  53.                     <tr><td colspan="2"><br/><br/><input type="button" onclick="validate_form()"  /></td></tr>
  54.  
  55.                     </table>
  56.                 </form>
  57.  
  58.     </body>
  59. </html>
Jan 24 '08 #1
1 2603
acoder
16,027 Expert Mod 8TB
If this is occurring in IE6 only, it will most likely be caused by the "name" id. Change it to something else, e.g. "nameValidation".
Jan 25 '08 #2

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

Similar topics

4
by: KathyB | last post by:
I have the following script in an html page: function goToPosition() { varGoTo = document.write(document.cookie("Position")); document.scrollTo(0, varGoTo); } </head> <body...
1
by: AA Arens | last post by:
To have the first character of a fiels capitalized AfterUppdate, I used the following script: Me!City = UCase$(Left$(Me!City, 1)) + Mid$(Me!City, 2) UCase (Left(Me!City, 1)) + Mid(Me!City, 2) ...
0
by: Sean OConnor | last post by:
I have three servers, public web server (e.g. web1), file server (file1), and web services server (service1). web1 is in the DMZ and file1 and service1 are internal. I'm calling the webservices...
2
by: hardrock | last post by:
Hello! I'm working with the prototype library version 1.4.0 and having a strange error lately. When I want to make an Ajax.Updater call, it basically works. But as soon as I put the call into...
7
by: John | last post by:
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...
10
RMWChaos
by: RMWChaos | last post by:
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."...
0
by: syedsarfaraz | last post by:
Hi There! Could anybody please help regarding the below issue. We had a COM+ component deployed on Windows 2000/NT machine it was working fine, I mean when it was being invoked from other...
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...
1
by: itxharsh | last post by:
/* While running the program a runtime error occurs."glibc detected" followed by a lot of memory address/instruction errors. Please help rectify this error.*/ /*Header file:"nonpreemptive.h" is as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.