Topic: [Checkbox] javascript and and form help

Hi Railsforum,

I have a checkbox that toggles on and off and disables by showing the box in grey.
If the page is refresh I want the checkbox to be uncheck.
When you do refresh the checkbox stays in whatever state it was in.
Is there a way to force a checkbox to be unchecked using javascript?

http://img235.imageshack.us/img235/122/checkattendancetc3.gif

This is my javascript toggle function

application.js

function attendance_mark_toggle()
{
    if ( $('attendance_mark').value == '0' )
    {
        $('attendance_mark_wrap').className = 'attendance_mark';
        $('attendance_mark').value = '1';
        $('attendance_mark').checked = 'checked';
    }
    else
    {   
        $('attendance_mark_wrap').className = 'attendance_mark disable';
        $('attendance_mark').value = '0';
    }   
}

Re: [Checkbox] javascript and and form help

I've solved the problem.

I added a blank checked value and made sure that in my form helpers that I made sure their values were set to 1 and false for being checked.

function attendance_mark_toggle()
{
    if ( $('attendance_mark').value == '0' )
    {
        $('attendance_mark_wrap').className = 'attendance_mark';
        $('attendance_mark').value = '1';
        $('attendance_mark').checked = 'checked';
    }
    else
    {   
        $('attendance_mark_wrap').className = 'attendance_mark disable';
        $('attendance_mark').value = '0';
        $('attendance_mark').checked = '';
    }   
}

<%= check_box_tag 'attendance_mark', '1', false, { :onclick => 'attendance_mark_toggle();' } %>

The toggle function I created is called in initializer function in the element tag body onLoad so the values that are set to 1 will be set to 0.