Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically uncheck a checkbox if another checkbox is checked through javascript?

Tags:

javascript

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.

like image 533
Sandipan Avatar asked Dec 03 '22 05:12

Sandipan


1 Answers

<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>
like image 145
bla Avatar answered Jan 12 '23 01:01

bla