changing row color on checkbox click

say for example i had something simple like this in a view:

<tr class="even"><td><%= check_box_tag(:task) %></td>

how would i add onclick to change the row color on a check and when the
check is removed?

maybe something like this?

page[task].addClassName('complete')

i'm not that familiar with javascript so i'm not sure how i would finish
this. thanks!

Scott Kulik wrote:

say for example i had something simple like this in a view:

<tr class="even"><td><%= check_box_tag(:task) %></td>

how would i add onclick to change the row color on a check and when the
check is removed?

maybe something like this?

page[task].addClassName('complete')

i'm not that familiar with javascript so i'm not sure how i would finish
this. thanks!

<%= check_box_tag :task, 1, false,
:onchange => "$(parentNode.parentNode).toggleClassName('complete')" %>

Mark Reginald James wrote:

Scott Kulik wrote:

i'm not that familiar with javascript so i'm not sure how i would finish
this. thanks!

<%= check_box_tag :task, 1, false,
:onchange => "$(parentNode.parentNode).toggleClassName('complete')" %>

--
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

perfect! thank you so much mark!

Scott Kulik wrote:

Mark Reginald James wrote:

Scott Kulik wrote:

i'm not that familiar with javascript so i'm not sure how i would finish
this. thanks!

<%= check_box_tag :task, 1, false,
:onchange => "$(parentNode.parentNode).toggleClassName('complete')" %>

--
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

perfect! thank you so much mark!

oops spoke a little too soon. the highlighting works great on firefox 3
but for some reason it acts a little weird on IE7.

the first check box i click doesn't do anything but then if i click
another check box the first check box row gets highlighted.

any idea what could be causing the incompatibility with IE?

Try adding `this`:

<%= check_box_tag :task, 1, false,
    :onchange => "$(this.parentNode.parentNode).toggleClassName('complete')" %>

Brandon Keepers wrote:

another check box the first check box row gets highlighted.

any idea what could be causing the incompatibility with IE?

Try adding `this`:

<%= check_box_tag :task, 1, false,
    :onchange =>
"$(this.parentNode.parentNode).toggleClassName('complete')" %>

--
--------------------------------------------------------------------------------
Training by Collective Idea: Ruby on Rails training in a vacation
setting
http://training.collectiveidea.com � San Antonio, TX � Jan 20-23

same thing :frowning:

i found some info here:

http://dev.rubyonrails.org/ticket/11078

and the link they reference
http://prototypejs.org/learn/extensions...there is a bit at the bottom:

// this will error out in IE:
$('someElement').parentNode.hide()
// to make it cross-browser:
$($('someElement').parentNode).hide()

so....i tried these ways:

$(this.parentNode.parentNode).toggleClassName('complete')

$($(this).parentNode.parentNode).toggleClassName('complete')

$($('make_step18').parentNode.parentNode).toggleClassName('complete')

make_step18 is the id of checkbox i was testing.

but they all produce the same weird result where they don't update until
i click a second time. first click always does nothing.

Scott Kulik wrote:

but they all produce the same weird result where they don't update until
i click a second time. first click always does nothing.

finally got it. it was the :onchange that was causing some issues. i
changed it to :onclick and all methods are now working with IE7.

thanks again everyone!