Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Scripting / September 2007

Tip: Looking for answers? Try searching our database.

Javascript problem with innerHTML

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RateTheBuilder - 31 Aug 2007 15:28 GMT
I am having trouble with the following function. I am trying to change the
ID of a hidden form object inside a table row. I have used alert() to test
where it breaks and it seems to be on the last line of the function where I
am trying to place the new text back into the table row. Anyone any ideas
where I'm going wrong as I'm not a great Javascript coder. Or even if you
know a better way to carry out what I am trying to do.

Thanks in advance.

this.onDrop = function(table, droppedRow) {
     var rows = table.tBodies[0].rows;
     var rowsCount = parseInt(rows.length);

     for (var x = 0; x <= rowsCount - 1; x++)
     {
         //Get string contents of row
          var curRowString = rows[x].innerHTML;

         //Find where ID tag is
          var IDStart = curRowString.indexOf("ID");

         //Find > immediately after ID tag
          var IDEnd = curRowString.indexOf(">", IDStart);

         //Get ID value
          var IDVal = curRowString.substring(IDStart+5,IDEnd)

         //Replace old ID with new ID
          var oldID = "ID" + IDVal;
          var newID = "ID" + (x+1);
          var newRowString = curRowString.replace(oldID, newID);

          //*********** Crashes on line below ***************
          rows[x].innerHTML = newRowString;
     }
}
intrader - 08 Sep 2007 20:54 GMT
> I am having trouble with the following function. I am trying to change the
> ID of a hidden form object inside a table row. I have used alert() to test
[quoted text clipped - 19 lines]
>           //Find > immediately after ID tag
>            var IDEnd = curRowString.indexOf(">", IDStart);
Not generally a good assumption to local the end of the id string

>           //Get ID value
>            var IDVal = curRowString.substring(IDStart+5,IDEnd)
[quoted text clipped - 6 lines]
>            //*********** Crashes on line below ***************
>            rows[x].innerHTML = newRowString;
In IE this replacement is not guaranteed to work
>       }
> }
What I would traverse the DOM element where the ID attribute is located,
and then simply replace the ID attribute.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.