FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

replace td value by innerHTML

 


AOP Web Development
Hello to all javascript coders, mmm i was starting to create now a web 2.0 application something but since i'm novice with javascript i would like to ask if how to replace the value of the <TD> on the table

let say

i have

<table>
<tr>
<td> old value</td>
</tr>
</table>
replace by


<table>
<tr>
<td> new Value</td>
</tr>
</table>

and other thing is how to delete a whole tr with multiple td let say


<table>
<tr>
<td> 2</td>
<td> Product</td>
<td> Description</td>
<td> Price</td>
<td> Edit Link</td>
<td> Delete Link</td>
</tr>
<tr>
<td> 1</td>
<td> Product</td>
<td> Description</td>
<td> Price</td>
<td> Edit Link</td>
<td> Delete Link</td>
</tr>
</table>
let say i want to delete the whole cell on Item#1 without refreshing the whole content.

hope you can share more about it Very Happy
alalex
the only way I know this can be done is placing a <div> inside each of the cells, and assgning a unique id to each of them.
But I dont recommend doing that, instead you should try to create the tables using css and divs, so that you'll have total control over their behaviour.

Whatever you do, the script for what you want to do is:
Code:
<script language="javascript" type="text/javascript">
<!--
function replace_value($new_value,$id){
   //First get the object by its id:
   var cell = document.getElementById($id);
   cell.innerHTML = $new_value;
}
-->
</script>

Example of usage:
Code:

<script language="javascript" type="text/javascript">
<!--
replace_value('<p>I am a new value</p>','cell4')
-->
</script>

Now that function will probably suit you better if it is triggered by a button:
Code:
onClick="replace_value('<p>I am a new value</p>','cell4')"


But that is up to you.
Any problem you find, ask here!
Luck Wink
alalex
Sorry forgot to tell you about deleting.
You can do it the same way, but this time replacing by a blanck value ''.
But remember that first you need to create the table using divs, for it will only work that way.
AOP Web Development
thanks for your share.. although i don't have a problem in handling with div or by using ID what i want is how to handle it by tables. as it is more quite complicated.. i see some infos that it can be done by nodes or getting the list of it. But hopefully you can also share with it.
alalex
O sorry, well I never really tried to do what you are trying, but I am guessing the the best way to do what you want to do is using Ajax.
I dont have a lot of experience with it, but from what I know it is possible to do what you are trying to do.
Luck Wink
AOP Web Development
No, it's okay man. heheh anyway thanks for your sharing.. Smile
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.