Solved

Edit a Cell's innerText and innerHTML

Posted on 2004-09-28
10
919 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 60
disable and enable textboxes in dataTable 7 45
Horizontal Full Calendar using php 5 34
Woo-commerce gallery not working properly 12 32
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

731 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