eevan79 Posted June 16, 2010 Share Posted June 16, 2010 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. Quote Link to comment Share on other sites More sharing options...
xenophobia Posted June 17, 2010 Share Posted June 17, 2010 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. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted June 17, 2010 Author Share Posted June 17, 2010 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)? Quote Link to comment Share on other sites More sharing options...
xenophobia Posted June 18, 2010 Share Posted June 18, 2010 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. =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.