Long backstory on this, and this seems to be the simplest solution. I have a table that will populate with user id’s from a database. I need to figure out a way to add a comma between id’s if there is more than one. The td id is username.
I’m not sure where to really start. I would need to index it and see if the html is > 1. And if so, add a comma between each word. Please help. This is a p.o.c forum and it doesn’t suit me to add/use jQuery, so I need to do it in vanilla JavaScript.
Here is the code that pulls it from the database:
if ($this->post['post_thanks_amount'] > 0 && $this->thread['isdeleted'] == 0)
{
$this->post['post_thanks_bit'] = fetch_thanks_bit($this->thread['forumid'], $thanks);
$this->post['post_thanks_user'] = $post_thanks_user;
$this->post['post_thanks_amount_formatted'] = vb_number_format($this->post['post_thanks_amount']);
$post_thanks_box = fetch_post_thanks_template($this->post);
}
And the output with one user is this:
<tr valign="top">
<td style="background:#E8E8E8;" colspan="2" class="alt1">
<div>
<a rel="nofollow" href="member.php?u=20420">ninja1</a>
<a rel="nofollow" href="member.php?u=26154">testuser</a>
</div>
</td>
</tr>
so after each <a...> if there is more than one, add a comma.
If ids is an array, then just use
join: