Solved

Edit a Cell's innerText and innerHTML

Posted on 2004-09-28
10
913 Views
Last Modified: 2006-11-17
Hi Experts,

I am trying to change a particular cell's innerText and innerHTML in my table...    May I ask how to do this...?

A sample code would be best...


Thanks in advanced experts...   =)
0
Comment
Question by:expert_mentos
  • 5
  • 5
10 Comments
 

Author Comment

by:expert_mentos
ID: 12167583
Here is my code...

<table id="tblOrders" cellspacing="0" cellpadding="0" border="1" bgcolor="#ffffff" align="left" width="700">
<tbody id="tbodyOrders">
    <tr>
        <td bgcolor="#ffffff" valign="center" align="center" width="17" height="24" class="crmlistView">
            <input type="checkbox" name="checkbox" value="checkbox">
        </td>
        <td bgcolor="#ffffff" valign="bottom" width="55" height="24" align="left" class="crmlistView">
            &nbsp;10010
            <input type="hidden" name="hdnOrdersItemCode" value="10010">
        </td>
    </tr>
</tbody>
</table>

<INPUT type="button" class="crm_Buttons" name="btnEditCell" value="Edit" onClick="EditCell()">
0
 
LVL 33

Accepted Solution

by:
sajuks earned 50 total points
ID: 12167599
//INNERHTML

<table id="tblOrders" cellspacing="0" cellpadding="0" border="1" bgcolor="#ffffff" align="left" width="700">
<tbody id="tbodyOrders">
    <tr>
        <td bgcolor="#ffffff" valign="center" align="center" width="17" height="24" class="crmlistView">
            <input type="checkbox" name="checkbox" value="checkbox">
        </td>
        <td id = "abc" bgcolor="#ffffff" valign="bottom" width="55" height="24" align="left" class="crmlistView">
            &nbsp;10010
            <input type="hidden" name="hdnOrdersItemCode" value="10010">
        </td>
    </tr>
</tbody>
</table>

<INPUT type="button" class="crm_Buttons" name="btnEditCell" value="Edit" onClick="document.getElementById('abc').innerHTML='NewValue';"">
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12167606
//innertext is IE only
<script>

function init()
{
document.getElementById("somewhat").innerText ="hello";
}
</script>
<body onload="init()">
<div id="somewhat">text</div>
</body>


0
 

Author Comment

by:expert_mentos
ID: 12168124
Will document.getElementById('abc').innerHTML='NewValue' totally deletes all the HTML inside the cell and replace with 'New Value'...?

Thanks again...   =)

0
 

Author Comment

by:expert_mentos
ID: 12176168
What if in my next row, I do have another td with id 'abc'...    Will it be getElementById('abc[0]') and getElementById('abc[1]')....?

Thanks again...!    =)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:sajuks
ID: 12176555
"
Will document.getElementById('abc').innerHTML='NewValue' totally deletes all the HTML inside the cell and replace with 'New Value'...?"
>>Yes.

"Will it be getElementById('abc[0]') and getElementById('abc[1]')"
Nope. What i've provided is an example fot you how to do it.

0
 

Author Comment

by:expert_mentos
ID: 12176594

Actually my table can have plenty of rows having the same number of columns, with each column has its unique id per row...

With this, may I ask how will I indicate that only 1 row (e.g. 2nd row) will change its column (document.getElementById('abc').innerHTML='NewValue')...?

Thanks again...!   =)


<table id="tblOrders" cellspacing="0" cellpadding="0" border="1" bgcolor="#ffffff" align="left" width="700">
<tbody id="tbodyOrders">
    <tr>
        <td bgcolor="#ffffff" valign="center" align="center" width="17" height="24" class="crmlistView">
            <input type="checkbox" name="checkbox" value="checkbox">
        </td>
        <td id = "abc" bgcolor="#ffffff" valign="bottom" width="55" height="24" align="left" class="crmlistView">
            &nbsp;10010
            <input type="hidden" name="hdnOrdersItemCode" value="10010">
        </td>
    </tr>
    <tr>
        <td bgcolor="#ffffff" valign="center" align="center" width="17" height="24" class="crmlistView">
            <input type="checkbox" name="checkbox" value="checkbox">
        </td>
        <td id = "abc" bgcolor="#ffffff" valign="bottom" width="55" height="24" align="left" class="crmlistView">
            &nbsp;10010
            <input type="hidden" name="hdnOrdersItemCode" value="10010">
        </td>
    </tr>
</tbody>
</table>
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12186770
The td id will be unique for each row , rite.
So you just need to pass the id to a function
something like

<script>

function init(sid)
{

document.getElementById(sid).innerHTML ="hello";
}
</script>



<table id="tblOrders" cellspacing="0" cellpadding="0" border="1" bgcolor="#ffffff" align="left" width="700">
<tbody id="tbodyOrders">
    <tr>
        <td bgcolor="#ffffff" valign="center" align="center" width="17" height="24" class="crmlistView">
            <input type="checkbox" name="checkbox" value="checkbox">
        </td>
        <td id = "abc" bgcolor="#ffffff" valign="bottom" width="55" height="24" align="left" class="crmlistView">
            &nbsp;10010
            <input type="hidden" name="hdnOrdersItemCode" value="10010">
        </td>
            <td>
    </tr>
</tbody>
</table>

<INPUT type="button" class="crm_Buttons" name="btnEditCell" value="Edit" onClick="init('abc')">
0
 

Author Comment

by:expert_mentos
ID: 12201247

It worked already...    Thanks...!
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12206003
Thanks for the points and grade
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now