473,289 Members | 1,848 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,289 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 2596
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.