/    Sign up×
Community /Pin to ProfileBookmark

Write to Table <TD> -TD id ? – Simple Question

So I use document.form_name.input_cell.value to write to a form… What do I do to write to a table cell? <td> or just on the html page instead of being contained in the form?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@jsakalosJun 11.2007 — So I use document.form_name.input_cell.value to write to a form... What do I do to write to a table cell? <td> or just on the html page instead of being contained in the form?[/quote]
If you have:
[code=html]
<td id="myId">
[/code]

you should be able to
[code=php]

document.getElementById('myId').innerHTML = "your_text";
[/code]

This works for sure for div's I haven't tried it for tds.
Copy linkTweet thisAlerts:
@c00lryguyJun 11.2007 — I'm 100% sure innerHTML works for TDs.
Copy linkTweet thisAlerts:
@hdoggauthorJun 11.2007 — could i put a div tag in a cell and do it that way? so it would be <td><div id=myid> </div></td>
Copy linkTweet thisAlerts:
@c00lryguyJun 11.2007 — Absolutely, thats exactly what I use with the current code I'm working on, but the innerHTML didn't work for the TD?
Copy linkTweet thisAlerts:
@JMRKERJun 11.2007 — Worked great for me with this simple test:
[code=php]
<html>
<head>
<title>Table ID test</title>
<script type="text/javascript">
function TDwrite() {
var cell = 'RC'+document.getElementById('RCcell').value;
var info = document.getElementById('RCinfo').value;
document.getElementById(cell).innerHTML = info;
}
</script>
</head>

<body>
<h1>Table ID Text</h1>
<input type="text" id="RCcell" value="">RC (00 to 44) <br />
<input type="text" id="RCinfo" value="">Information
<button onClick="TDwrite()">Write It</button>
<p />

<script type="text/javascript">
var str = '<table border="1">';
var cell = '';
for (r=0; r<5; r++) {
str += '<tr>';
for (c=0; c<5; c++) {
cell = 'RC'+r.toString()+c.toString();
str += '<td id="'+cell+'">'+cell+'</td>';
}
str += '</tr>';
}
str += '</table>';
document.write(str);
</script>
</body>
</html>
[/code]

Don't know if I'll ever need it, but it's nice to know it can be done! ?
Copy linkTweet thisAlerts:
@hdoggauthorJun 11.2007 — Hey... works great! thanks a bunch!

Cheers-

Hyrum
×

Success!

Help @hdogg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...