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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.