SilentQ-noob- Posted September 4, 2007 Share Posted September 4, 2007 Hi, what I want to do is move text from one cell to another in a table. I've been looking for ways to do this and came across the innerHTML function. I'm not quite sure how to get started (i'm new to programming in general). Basically I want there to be text in box one of the table, and then when I click a link below for example "move to cell 2" it moves the text there. ANY help would be greatly appreciated!! <body> <script type="text/javascript"> <div id="cell1">document.write("TEXT")</div> function moveText(newPlace){ document.getElementById("test").innerHTML=newPlace } // This is a mess, I really dont know how to get started </script> <table width="500" height="500" border="1" cellspacing="0" cellpadding="0"> <tr> <td id="box1"> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </body> Link to comment https://forums.phpfreaks.com/topic/67958-solved-innerhtml-need-help/ Share on other sites More sharing options...
php_tom Posted September 4, 2007 Share Posted September 4, 2007 Try this: <body> <script type="text/javascript"> function moveText(){ var tmp = document.getElementById("cell1").innerHTML document.getElementById("cell1").innerHTML=document.getElementById("cell2").innerHTML; document.getElementById("cell2").innerHTML = tmp; } </script> <table width="500" height="500" border="1" cellspacing="0" cellpadding="0"> <tr> <td width='50%'><div id="cell1">Text</div></td> <td width='50%'><div id="cell2"> </div></td> </tr> <tr> <td width='50%'><div id="cell3"> </div></td> <td width='50%'><div id="cell4"> </div></td> </tr> </table> <input type='button' onclick='moveText()' value='Move Text' /> </body> It switches the text in cell 1 to cell 2 and vice versa. Hope it's what you wanted. Link to comment https://forums.phpfreaks.com/topic/67958-solved-innerhtml-need-help/#findComment-341648 Share on other sites More sharing options...
SilentQ-noob- Posted September 5, 2007 Author Share Posted September 5, 2007 Thats exactly what I was looking for, thanks. Link to comment https://forums.phpfreaks.com/topic/67958-solved-innerhtml-need-help/#findComment-342169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.