Hi chich,

As everyone has mentioned, you will need unique IDs for your HTML
elements. Fortunately, Rails 2.0 has a helper method that will
generate unique IDs for elements given an ActiveRecord object. div_for
is very easy to use:

<% trainees.each do |trainee| %>
  <% div_for trainee do %>
    <%= link_to_function h(trainee.name),
"my_javascript_function(#{trainee.id})", :class => 'LINKSON' %>
  <% end %>
<% end %>

...

<script type="text/javascript">
function my_javascript_function(id) {
  $("trainee_" + id).class = "LINKSOFF";
}
</script>

So, say you have a trainee record with ID 8, then div_for(trainee)
would generate:
<div id="trainee_8"></div>


Hope this helps.

Jason Arora

On Apr 14, 7:34 am, chich <[EMAIL PROTECTED]> wrote:
> How can I  control a div from a javascript function.
> For example if i have a product and has an id=8 and this product has 3
> trainees
> so when i click on something  i should see the 3 trainees name for
> this product.
> in the code i created a div with id="T<?=product_id?>" (id=T8)  class
> ="LINKSOFF" (hidden)
> how can i turn the class to class="LINKSON" from a javascript
> function.
> The problem is that when i have many div with the same id and write
> class="LINKSON" i can not see the div.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to