4

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.

3 Answers 3

9
<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>
Sign up to request clarification or add additional context in comments.

Comments

6

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>

Comments

3

If you are using jquery than

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.