473,405 Members | 2,167 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.

innerHTML IE Problem, please help!

2
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 11393
ilia
2
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 Expert Mod 8TB
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.dtd">

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

<script language = "Javascript">
var activeRow = 0;
function setActiveRow(el) {
var rows = document.getElementById('movingTable').childNodes;
for(var i = 0; i < rows.length; i++) {
if(rows[i] == el) {
activeRow = i;
break;
}
}
}

function getSwapRow(move)
{
var rows = document.getElementById('movingTable').childNodes;
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(move) {
var rows = document.getElementById('movingTable').childNodes;
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(rows[activeRow+move]);
}

function moveRow(cell, move) {
setActiveRow(cell.parentNode);
moveActiveRow(move);
}

</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="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">2</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">3</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">4</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">5</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">6</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">7</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
<div>
<div class="col1">8</div>
<div class="col2" onClick="moveRow(this, 1)">Down</div>
<div class="col3" onClick="moveRow(this, -1)">Up</div>
<div class="spacer"></div>
</div>
</div>
</body>
</html>
[/html]
May 18 '06 #3
pigfox
1
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
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. ...
4
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,...
8
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...
7
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...
1
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 = "";...
2
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...
5
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: ...
1
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...
5
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.