Jump to content

[SOLVED] innerHTML - need help


SilentQ-noob-

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.