473,769 Members | 7,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

innerHTML IE Problem, please help!

2 New Member
Hi All,

I am a newbie in terms of Javascript, I found some code on the net to swap rows in a table using innerHTML, this works fine in Firefox but IE is complaining, after some googling around I found that innerHTML is read only for tables in IE which is a problem, please see my code below.

I need urgent help if anyone has an idea or a helpfull link, any help will be greatly appreciated!

PS: dont mind the PHP
CODE BELOW ---
Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. $array = explode(",", %4$sPOST["order"]);
  4.  
  5. for($i=0; $i<count($array); $i++)
  6. {
  7. $newold[$i]['new_position'] = $i+1;
  8. $newold[$i]['old_position'] = $array[$i];
  9. if ($newold[$i]['new_position'] != $newold[$i]['old_position'])
  10. {
  11. echo "<b>SQL is:</b> UPDATE -table name- SET step = ".$newold[$i]['new_position']." WHERE step = ".$newold[$i]['old_position']."<br>";
  12. }
  13. }
  14. ?>
  15. <html>
  16. <head>
  17. <title>Untitled Document</title>
  18. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  19. <script language = "Javascript">
  20. var activeRow = 0;
  21. function setActiveRow(el) {
  22. var rows = document.getElementById('movingTable').rows;
  23. for(var i = 0; i < rows.length; i++) {
  24. if(rows[i] == el) activeRow = i;
  25. }
  26. }
  27.  
  28. function moveActiveRow(move) {
  29. var rows = document.getElementById('movingTable');
  30. var oldRow = rows.rows[activeRow].innerHTML;
  31. var newRow = rows.rows[activeRow+move].innerHTML;
  32. alert(newRow);
  33. //swap bug in IE
  34. rows[activeRow].innerHTML = newRow;
  35. rows[activeRow+move].innerHTML = oldRow;
  36. //end swap
  37. setActiveRow(rows[activeRow+move]);
  38. }
  39.  
  40. function moveRow(cell, move) {
  41. setActiveRow(cell.parentNode);
  42. moveActiveRow(move);
  43. }
  44.  
  45. function doSubmit() {
  46. var rows = document.getElementById('movingTable').rows;
  47. var ret = new Array();
  48. for(var i = 0; i < rows.length;i++) {
  49. ret[i] = rows[i].getElementsByTagName('td')[0].innerHTML;
  50. }
  51. return ret;
  52. }
  53. </script>
  54. </head>
  55. <body>
  56. <table width="300" border="2" cellspacing="0" cellpadding="0" id="movingTable">
  57. <tr>
  58. <td>1</td>
  59. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  60. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  61. </tr>
  62. <tr>
  63. <td>2</td>
  64. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  65. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  66. </tr>
  67. <tr>
  68. <td>3</td>
  69. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  70. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  71. </tr>
  72. <tr>
  73. <td>4</td>
  74. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  75. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  76. </tr>
  77. <tr>
  78. <td>5</td>
  79. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  80. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  81. </tr>
  82. <tr>
  83. <td>6</td>
  84. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  85. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  86. </tr>
  87. <tr>
  88. <td>7</td>
  89. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  90. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  91. </tr>
  92. <tr>
  93. <td>8</td>
  94. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  95. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  96. </tr>
  97. </table>
  98.  
  99. <form name="form1" method="post" action="sample.php" onSubmit="this.order.value=doSubmit()">
  100. <input type="hidden" name="order">
  101. <input type="submit" name="Submit" value="Submit">
  102. </form>
  103. </body>
  104. </html>
  105.  
May 17 '06 #1
3 11441
ilia
2 New Member
sorry their is a bug...

please see corrected code below:

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. $array = explode(",", %4$s POST["order"]);
  4.  
  5. for($i=0; $i<count($array); $i++)
  6. {
  7. $newold[$i]['new_position'] = $i+1;
  8. $newold[$i]['old_position'] = $array[$i];
  9. if ($newold[$i]['new_position'] != $newold[$i]['old_position'])
  10. {
  11. echo "<b>SQL is:</b> UPDATE -table name- SET step = ".$newold[$i]['new_position']." WHERE step = ".$newold[$i]['old_position']."<br>";
  12. }
  13. }
  14.  
  15.  
  16.  
  17. //print("<pre>");
  18. //print_r($newold);
  19. //print("</pre>");
  20. ?>
  21. <html>
  22. <head>
  23. <title>Untitled Document</title>
  24. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  25. <script language = "Javascript">
  26. var activeRow = 0;
  27. function setActiveRow(el) {
  28. var rows = document.getElementById('movingTable').rows;
  29. for(var i = 0; i < rows.length; i++) {
  30. if(rows[i] == el) activeRow = i;
  31. }
  32. }
  33.  
  34. function moveActiveRow(move) {
  35. var rows = document.getElementById('movingTable').rows;
  36. var oldRow = rows[activeRow].innerHTML;
  37. var newRow = rows[activeRow+move].innerHTML;
  38.  
  39. //swap bug in IE
  40. rows[activeRow].innerHTML = newRow;
  41. rows[activeRow+move].innerHTML = oldRow;
  42. //end swap
  43. setActiveRow(rows[activeRow+move]);
  44. }
  45.  
  46. function moveRow(cell, move) {
  47. setActiveRow(cell.parentNode);
  48. moveActiveRow(move);
  49. }
  50.  
  51. function doSubmit() {
  52. var rows = document.getElementById('movingTable').rows;
  53. var ret = new Array();
  54. for(var i = 0; i < rows.length;i++) {
  55. ret[i] = rows[i].getElementsByTagName('td')[0].innerHTML;
  56. }
  57. return ret;
  58. }
  59. </script>
  60. </head>
  61. <body>
  62. <table width="300" border="2" cellspacing="0" cellpadding="0" id="movingTable">
  63. <tr>
  64. <td>1</td>
  65. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  66. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  67. </tr>
  68. <tr>
  69. <td>2</td>
  70. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  71. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  72. </tr>
  73. <tr>
  74. <td>3</td>
  75. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  76. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  77. </tr>
  78. <tr>
  79. <td>4</td>
  80. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  81. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  82. </tr>
  83. <tr>
  84. <td>5</td>
  85. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  86. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  87. </tr>
  88. <tr>
  89. <td>6</td>
  90. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  91. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  92. </tr>
  93. <tr>
  94. <td>7</td>
  95. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  96. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  97. </tr>
  98. <tr>
  99. <td>8</td>
  100. <td style="cursor: hand;" onClick="moveRow(this, 1)">Down</td>
  101. <td style="cursor: hand;" onClick="moveRow(this, -1)">Up</td>
  102. </tr>
  103. </table>
  104.  
  105. <form name="form1" method="post" action="sample.php" onSubmit="this.order.value=doSubmit()">
  106. <input type="hidden" name="order">
  107. <input type="submit" name="Submit" value="Submit">
  108. </form>
  109. </body>
  110. </html>
  111.  
May 18 '06 #2
Banfa
9,065 Recognized Expert Moderator Expert
Instead of tables use Divs and CSS to make them look like tables, the only disadvantage of this is that you have to explicitly set the width of each column, like this (works in IE and Firefox)

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html>
<head>
<title>Tables Using CSS</title>

<script language = "Javascript ">
var activeRow = 0;
function setActiveRow(el ) {
var rows = document.getEle mentById('movin gTable').childN odes;
for(var i = 0; i < rows.length; i++) {
if(rows[i] == el) {
activeRow = i;
break;
}
}
}

function getSwapRow(move )
{
var rows = document.getEle mentById('movin gTable').childN odes;
var delta = move<0 ? -1 : 1;
var end = move<0 ? -1 : rows.length;

for( var i = activeRow+delta ; i != end; i += delta ) {
if ( rows[i].nodeName == "DIV" )
{
move -= delta;

if (move == 0) {
return i;
}
}
}

/* Only get here if attempted invalid operation
like move up top row */
return -1;
}

function moveActiveRow(m ove) {
var rows = document.getEle mentById('movin gTable').childN odes;
var swapRow = getSwapRow(move );

if (swapRow == -1 )
return;

var oldRow = rows[activeRow].innerHTML;
var newRow = rows[swapRow].innerHTML;
//alert(oldRow + " : " + activeRow +" : " + (swapRow) + " : " + newRow);
rows[activeRow].innerHTML = newRow;
rows[swapRow].innerHTML = oldRow;
setActiveRow(ro ws[activeRow+move]);
}

function moveRow(cell, move) {
setActiveRow(ce ll.parentNode);
moveActiveRow(m ove);
}

</script>

<style>
#movingTable {
width: 300px;
border: 2px solid gray;
}

#movingTable div { /* this is the row */
clear: both;
margin: 0;
padding: 0;
}

#movingTable div div { /* this is the cell */
float: left;
clear: none;
border: 1px solid gray;
margin: 0;
padding: 0;
cursor: pointer;
}

/* Set column widths these can be set separately
and named appropriately if required */
#movingTable div .col1, #movingTable div .col2, #movingTable div .col3 {
width: 98px;
}

#movingTable div .spacer {
float: none;
clear: both;
border: 0;
margin: 0;
padding: 0;
cursor: default;
overflow: hidden;
height: 1px;
}
</style>
</head>
<body>
<div id="movingTable ">
<div>
<div class="col1">1</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">2</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">3</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">4</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">5</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">6</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">7</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
<div>
<div class="col1">8</div>
<div class="col2" onClick="moveRo w(this, 1)">Down</div>
<div class="col3" onClick="moveRo w(this, -1)">Up</div>
<div class="spacer"> </div>
</div>
</div>
</body>
</html>
[/html]
May 18 '06 #3
pigfox
1 New Member
This solution is really good, but does anyone know how to create a new row via an "Add Row" link and also have another link for deleting the row the delete link is on while the numbering is autoupdated.
Dec 22 '06 #4

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

Similar topics

3
1994
by: Jason | last post by:
I have a web page that contains textareas. These are dynamically added via asp when the page loads based on database records. The user also has the ability to add more text areas via innerhtml. If the user clicks the add text area button too fast or too many times.. they will get the following error: Internet Explorer Has Encountered a Problem and Needs to Close. After reading msdns page about this error I doubt that there is a fix...
4
1819
by: Anders Nielsen | last post by:
Hi :-) I'm currently working with innerHTML , but it is giving me some problems with " and '. Basically (there is also some ASP involved), my problem looks like this: I would like to, dynamically, insert the following html into a table cell: <span id="soeskende5slet" style="position: absolute; right: 70px; cursor:hand; text-decoration:underline;" onClick="soeskendeSlet('5','Anders
8
7773
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this way the main page never gets refreshed. It works perfectly under IE, but with Mozilla and Firefox I got a problem : there is a space before the thing I want to display everytime I use ".innerHTML".
7
9338
by: garthusenet | last post by:
I have a fairly complicated application written in Javascript+DOM, and I've run into an odd problem that only shows up in Safari. Basically, after setting innerHTML of a DIV, the div ends up empty instead of with the correct content. In fact, the children of the DIV all vanish, and it becomes impossible to set the contents thereafter. The much simplified scenario: <div id='divname'> hello
1
2198
by: huzheng001 | last post by:
I have develop a on-line dictionary website, http://www.stardict.org I meet a problem: Here is two lines of js codes: document.getElementById("wordlist").innerHTML = ""; document.getElementById("definition").innerHTML = "line1<br>line2"; The corresponding html codes are: <table width="100%"> <tr> <td width="25%" valign="top"><div id="wordlist" width="100%" style=' overflow-y:auto; height:352px;'></div></td>
2
4757
by: m0nkeymafia | last post by:
I have spent the past few weeks trying to figure a way around this problem, and have yet to find a good enough solution. Internet Explorer leaks memory when I update a div container using innerHTML, this does not occur in firefox. This would not be a problem except the webpage is required to be left on for weeks on end without being restarted. I presume the issue with innerHTML is that Internet Explorer apparently parses what you give...
5
1907
by: Andrew Hedges | last post by:
Wherein I attempt to debunk some myths about the relative merits of the two methods for programmatically adding content to a web page: http://www.newfangledtelegraph.com/blog/entry/the-need-for-speed-innerhtml-versus-dom-manipulation/ Cheers, -Andrew ----- andrew@hedges.name / http://andrew.hedges.name/
1
1548
by: ppRaistlin | last post by:
Hi, I understand that it s a very rare question that I m ready to ask and that only few people can actually test but a theoric explanation and solution will be really grateful. Here is my problem : I have a computer with 3 video cards and 6 monitors plugged (for business purpose). The resolution for each monitor is 1280x1024 On each of this monitor I have a IE browser (full screen) showing the
5
1567
by: harikumarmpl | last post by:
Hi to all Here is the code i am trying for <html> <head> <title>XMLHttpRequest</title> <script type="text/javascript">
0
9589
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
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
2
3565
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.