tags:

views:

215

answers:

3

I have a checkbox Birthdate which shows the mm/dd only.And below it there is another checkbox called ShowYear which shows the year and this checkbox is only visible if the Bithdate checkbox is checked.

Now I want to uncheck the ShowYear checkbox automatically if the Birthdate checkbox is unchecked through javascript.

+4  A: 

First, give your check boxes ids eg:

<input type="checkbox" id="birth" />
<input type="checkbox" id="year" />

Javascript:

<script type="text/javascript">
 window.onload = function(){
    var birth = document.getElementById('birth');
    var year = document.getElementById('year');

    if (birth.checked == false)
    {
      year.checked = false;
    }
 }
</script>
Sarfraz
+2  A: 
<input id="cbxBirthDate" type="checkbox" onClick="javascript:uncheckShowYear(this);" />
<input id="cbxShowYear" type="checkbox" />


<script language="javascript" type="text/javascript">
function uncheckShowYear(obj)
        {
            if (obj.checked == false)
            {
                document.getElementById("cbxShowYear").checked = false;
            }
        }
</script>
Lee Sy En
+1  A: 

If you are using jquery than

$(document).redy( function a()
{
   if (  $('#birth').is(':checked'))
    {
       $('#year').attr('checked', false);
    }
});
Pranay Rana