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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.