I have a specific question, I have a link in a table in the third column of each row, when the user clicks that link he loads some ajax and updates the page, what I want to also happen is that in the 2nd column of the row where the link is, change the td’s class from false to true, and the value from No to Yes.
Thanks!
Update!
Code Example:
The 2nd column still doesn’t get updated on click, perhaps this is because the div where the table is located gets hidden onclick? Anyways here’s what I’ve tried:
<tr>
<td>00839</td>
<td class="false" style="text-align:left;">No</td>
<td>
<a href="#"
onclick="Element.hide('ajax-instruction-view');;
new Ajax.Updater('ajax-instruction-view', '/tasks/show_ajax/839', {asynchronous:true, evalScripts:true, onComplete:function(request){new Effect.Appear("ajax-instruction-view",{});window.scrollTo(0,0);
link = $(link);
var row = link.up('tr');
var cell = row.down('td').next('td');
cell.update('Yes');},
parameters: 'authenticity_token='encodeURIComponent('SYWsdBTWlz17u9HmPXA2R9WmBfZn67g/IAMGyhHEwXw=')}); return false;"
>
Instructions-Notice Board
</a>
</td>
<td>19/04/10</td>
<td class="false">21/04/10</td>
<td class="false" style="text-align:left;">None.</td>
</tr>
It sounds as though at some point, you have a reference to the link the user clicked (either because you have a
clickhandler on it or because you’re using event delegation and finding it after a click on the table). Starting with a reference to that link, you can use Prototype’s DOM traversal stuff to find the second table cell:Edit Based on your response to rahul, I would change your link
onclickto:…and this would be
handleLinkClick:That uses
Element#up,Element#next,Element#hasClassName,Element#addClassName,Element#removeClassName, andElement#update; docs for them here.Optional things to consider:
onclickattribute, you could useElement#observe.But the above should work.