/    Sign up×
Community /Pin to ProfileBookmark

Need help with home-made code

[CODE]document.getElementById(‘userlinks’).style.display = “none”;
qx = document.getElementById(‘userlinks’).innerHTML;
document.getElementById(‘usercontrols’).innerHTML = qx;[/CODE]

It’s currently putting all the data in the un-editable #userlinks field into a new ID class, which I re-apply to my forums using a <div> tag. This is all working fine, however, I would like a different effect.

I would like to have the code take the information in the first <td> tag, and place that into one new variable, then have another variable take the information from the second <td> tag. That way I can have the two sections separate!

Here’s the block HTML:

[code=html]<table width=”100%” id=”userlinks” cellspacing=”6″>
<tr>
<td><strong>Logged in as: <a href=’http://z11.invisionfree.com/GreytekIV2/index.php?showuser=1′>Shifty</a></strong> ( <a href=’http://z11.invisionfree.com/GreytekIV2/index.php?act=Login&amp;CODE=03′>Log Out</a>&nbsp;&middot; <b><a href=’http://z11.invisionfree.com/GreytekIV2/admin.php’ target=’_blank’>Admin CP</a></b> &middot; <b><a href=’http://z11.invisionfree.com/GreytekIV2/index.php?act=modcp&amp;forum=’>Mod CP</a></b> )</td>

<td align=’right’>
<b><a href=’http://z11.invisionfree.com/GreytekIV2/index.php?act=UserCP&amp;CODE=00′ title=’Edit my settings, such as signature, avatar and more…’>My Controls</a></b> &middot; <a href=’http://z11.invisionfree.com/GreytekIV2/index.php?act=Msg&amp;CODE=01′>Inbox (0)</a>
&middot; <a href=’http://z11.invisionfree.com/GreytekIV2/index.php?act=Search&amp;CODE=getnew’>View New Posts</a> &middot; <a href=’javascript:buddy_pop();’ title=’View posts since your last visit, moderator lists and more…’>My Assistant</a></td>
</tr>

</table>[/code]

I cannot seem to figure out how to do this myself. If you could assist me, I’d be very, very grateful!

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@DokAug 07.2007 — I'm not really sure about what you want but this will read the data from each column in the first row into a variable
[CODE]function getData() {
// Variable for storing column data
var column = new Array();
// Get table
var table = document.getElementById('userlinks');
// Foreach column in first row
var length = table.firstChild.childNodes.length;
for (var i=0; i<length; i++) {
// Copy data to some variable
column.push(table.firstChild.childNodes[i].firstChild.nodeValue);
}
}[/CODE]
Copy linkTweet thisAlerts:
@ShiftyauthorAug 07.2007 — Hmm, it looks like you're on the right lines.

I want to have two separate variables, one containing the contents of the first table cell, the second containing the contents of the second table cell. Does that make more sense?
Copy linkTweet thisAlerts:
@DokAug 07.2007 — If you only have two cells why don't you just give each td an id attribute and use document.getElementById() ?
Copy linkTweet thisAlerts:
@ShiftyauthorAug 07.2007 — I can't edit the core HTML ? it's preset by the forum system.
Copy linkTweet thisAlerts:
@DokAug 07.2007 — The content of the cells are in column[0] and column[1] in my previous post
Copy linkTweet thisAlerts:
@ShiftyauthorAug 08.2007 — Right, okay, I must be having an off-week or something here, though I'm not expert anyway!

function getData() {
// Variable for storing column data
var column = new Array();
// Get table
var table = document.getElementById('userlinks');
// Foreach column in first row
var length = table.firstChild.childNodes.length;
for (var i=0; i&lt;length; i++) {
// Copy data to some variable
column.push(table.firstChild.childNodes[i].firstChild.nodeValue);
}
}


Say I wanted to display those 'captured' cells using this sort of method:
[code=html]<div id="">(Cell 1)</div><div id="">(Cell 2)</div>[/code]

Would your code be suitable? If so, I'm sorry to ask, could you walk me through it?
Copy linkTweet thisAlerts:
@ShiftyauthorAug 09.2007 — I'm sorry to pester, but I still need a little more help.
Copy linkTweet thisAlerts:
@DokAug 10.2007 — Try this
[code=html]<div id="cell1"></div><div id="cell2"></div>[/code]
and this
[CODE]function getData() {
// Variable for storing column data
var column = new Array();
// Get table
var table = document.getElementById('userlinks');
// Foreach column in first row
var length = table.firstChild.childNodes.length;
for (var i=0; i<length; i++) {
// Copy data to some variable
column.push(table.firstChild.childNodes[i].firstChild.nodeValue);
}
// Insert into cell 1
document.getElementById('cell1').innerHTML = column[0];
// Insert into cell 2
document.getElementById('cell2').innerHTML = column[1];
}[/CODE]
Copy linkTweet thisAlerts:
@ShiftyauthorAug 10.2007 — Thank-you for all your time ?
Copy linkTweet thisAlerts:
@sankarshanaAug 11.2007 — i want to display the values of checkboxs inthe text area plz tell me
×

Success!

Help @Shifty 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.21,
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,
)...