Jump to content

getElementById from rows/cells


eevan79

Recommended Posts

Hi,

I'm not so good with DOM and trying to implement "reply" and "quote" function in my script.

How to get text from specific row?

Here is my template for posting (content):

<td valign="top" align="left" class="caption1" colspan="3"><div class="postedText">{$posterText}</div>{$deleteBox}</td>

So I need to get {$posterText} (and send it to textarea).

 

And this is table for username who posted:

<td class="pauthor txtL"><span class="username"><div align="center"><img src="{$main_url}/img/s.gif" style="width:12px;height:9px;padding-top:6px" alt="{$l_author}" /> {$pLink1}{$posterName}{$pLink2}</div></span></td>
<td class="txtR noWrap pauthor"><div class="txtSm2">{$postDate}{$editedBy}{$viewIP} {$l_sepr} <a id="msg{$cols[6]}" name="msg{$cols[6]}" href="#msg{$cols[6]}" class="txtSm">#{$anchor2}</a><span class="txtSm"></div></td>
</tr>

Where is {$pLink1}{$posterName}{$pLink2} username of person who write message.

So I need to get following elements (output from specific table or row):

[quote={$pLink1}{$posterName}{$pLink2}]{$posterText}][/quote]

or

[quote=[b]{$posterName}[/b]]{$posterText}][/quote]

whatever...

I have tried to read some instructions from http://www.w3schools.com/JS/js_ex_dom.asp but cant get content from specific table or row.

 

Help?

 

Thanks.

Link to comment
Share on other sites

To get the content inside a HTML, use document.getElementById("youElementId").innerHTML

 

Eg:

<div id="element1">Hello world!</div>

 

<script language="JavaScript" type="text/javascript">

var text = document.getElementById("element1").innerHTML;

alert("Here is your text: " + text);

</script>

 

So you just need to give an ID to your element and grab the content by using innerHTML property.

Link to comment
Share on other sites

Yes, but I always get content from first message. Probably I need to set array for "reply" button or message DIVs. For example:

________________

MESSAGE1

------------------

[REPLY BUTTON]

________________

MESSAGE2

------------------

[REPLY BUTTON]

________________

..etc

 

This is structure of my viewposts template.

How to get content of MESSAGE (above reply but.) when I click [REPLY BUTTON] (how to set arrays for divs, or reply button to make it work)?

 

Link to comment
Share on other sites

This is depend on how you draw your table. Are you using PHP? Probably your code will loop all the message and print it out on a table's row.

 

So what you have to do is append the record's ID into each row. So each row you will have a different ID:

<tr id="row_1">

...

</tr>

<tr id="row_2">

...

</tr>

 

With that, you can loop all the row and get the content in JavaScript:

for (var i=1,limit=100; i < limit; i++) {

    var row = document.getElementById("row_" + i) {

        if (row === null) {

            alert("End of row: " + i); break ;

        } else {

            var text = row.innerHTML; // Here is your text.

        }

    }

}

 

This is just the concept, actually implementation has to depends on you. =)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.