Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 16th, 2005, 04:24 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically Changing the content of a table cell

I want to dynamically change the content of a table cell.

Right now I am able to change the content using innerText property.

But I have a cell which has a link in it. I want to dynamically change
the name on the link. In this case innerText would remove the link property and put a plain text in the cell.

I tried using innerHtml , it didnt change anything at all...

Portions of my code...
some parameters in the innerhtml are dynamic and they are all having valid values.

var htmltxt = '<a href="javascript:OpenDetailsPage(' + "'" +
                configid + "'" + ');">' +
             argsret[0].toString() + ' </a>';

alert(htmltxt);

// cell.innerText = argsret[0].toString() ;
    cell.innerHtml = htmltxt;
    row.cells[c+1].innerText = argsret[1].toString();


cell and row are the current row and cell objects.

Reply With Quote
  #2 (permalink)  
Old February 17th, 2005, 09:20 AM
Registered User
 
Join Date: Feb 2005
Location: Memphis, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi asdasd,

I tested this is IE6 and FF, seems you can use innerHTML on these browsers.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<script type="text/javascript">
var myLinks = ["http://www.google.com", "http://www.yahoo.com"];
var myTexts = ["Google", "Yahoo"];
var k = 0;

function chgLink(x)
{
k = (k == 2)? 0 : k;
var el = document.getElementById(x);
el.innerHTML = myTexts[k];
el.title = myTexts[k];
el.href = myLinks[k];
k++;
}
</script>
</head><body>
<table border="1">
<tr><td>
<a id="1" href="">Test</a>
</td></tr>
</table>
<form>
<input type="button" onclick="chgLink(1)" value="Test Change">
</form></body></html>

HTH

HTH
Lrnmore
Reply With Quote
  #3 (permalink)  
Old February 17th, 2005, 04:20 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<script type="text/javascript">
var myLinks = ["http://www.google.com", "http://www.yahoo.com"];
var myTexts = ["Google", "Yahoo"];
var k = 0;

function chgLink(x)
{
k = (k == 2)? 0 : k;
var el = document.getElementById('ta');
alert(el.rows[0].cells[0].innerHTML);
alert(el.rows[0].cells[0].title);
alert(el.rows[0].cells[0].href);
el.rows[0].cells[0].innerHTML = myTexts[k];
el.rows[0].cells[0].title = myTexts[k];
el.rows[0].cells[0].href = myLinks[k];
k++;
}
</script>
</head><body>
<table border="1" id="ta">
<tr><td>
<a id="1" href="">Test</a>
</td></tr>
</table>
<form>
<input type="button" onclick="chgLink(1)" value="Test Change">
</form></body></html>

Thanks for you reply, I tried your code it works, but if there is no Id for the link element, and if I want to change it through the table ID, it is not working.

I have pasted the modified code, Can you pls check and tell me why its not working now..

Using IE6 only

Reply With Quote
  #4 (permalink)  
Old February 17th, 2005, 06:50 PM
Registered User
 
Join Date: Feb 2005
Location: Memphis, TN, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

asdasd,

This page has 2 buttons, maybe you can spot why innerHTML didn't work for you
before.

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<script type="text/javascript">
var myLinks = ["http://www.google.com", "http://www.yahoo.com"];
var myTexts = ["Google", "Yahoo"];
var k = 0;

function chgLink(x)
{
k = (k == 2)? 0 : k;
var elTab = document.getElementById('ta');
var elLink = document.getElementById(x);
alert(elTab.rows[0].cells[0].innerHTML);
elLink.innerHTML = myTexts[k];
elLink.title = myTexts[k];
elLink.href = myLinks[k];
k++;
}

function chgCell(){
var html = '<a href="http://www.msn.com">MSN</a>';
var elTab = document.getElementById('ta');
elTab.rows[1].cells[0].innerHTML = html;
}

</script>
</head><body>
<table border="1" id="ta">
<tr><td>
<a id="1" href="">Test</a>
</td></tr>
<tr><td>
test
</td></tr>
</table>
<form>
<input type="button" onclick="chgLink(1)" value="Test ChangeA">
<input type="button" onclick="chgCell()" value="Test ChangeB">
</form></body></html>

HTH
Lrnmore
Reply With Quote
  #5 (permalink)  
Old February 18th, 2005, 12:44 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

var htmltxt ='<a href="javascript:OpenDetailsPage(' + "'" + configid + "'" + ');">' +
 argsret[1].toString() + ' </a> ' ;

var htmlvar = cell.innerHTML;
cell.innerHTML = htmltxt;


It worked if I use cell object directly. TABLe.row.cell didnt work.
TABLE doesnt support inner html , maybe its due to that..

Thanks for your help...

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically changing table location csloanATYC BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 November 6th, 2008 01:32 PM
dynamically changing the destination table premaanand SQL Server DTS 1 April 10th, 2006 03:37 PM
Capture cell value before changing it chp Excel VBA 2 March 15th, 2006 02:40 PM
if the cell content is a part of another cell cont sriramus Excel VBA 1 November 15th, 2005 09:20 AM
Datagrid cell content value sinba Beginning VB 6 1 August 24th, 2004 01:58 PM



All times are GMT -4. The time now is 01:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.