How to check or uncheck a checkbox using the id of the checkbox

I have a java script function named showInfo(). Show info is passed the name/id of a specific check box control. Now I want to be able to check or uncheck the check box control based upon the control Id that I pass in to the Java script function? I have tried using getElementById but that isn't working. Does
anyone know how I can check the check box based upon the id of the check box control using Java Script?

function showInfo(idOfCheckBox)
{
    document.getElementById(idOfCheckBox).checked = true;
}
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
your function should work just fine.

are you passing the correct id into your function?

Test example below:
<html>
<head>

<script>
    function showInfo(idOfCheckBox) {
        document.getElementById(idOfCheckBox).checked = true;
    }
</script>
    Test 1<input id="Checkbox1" type="checkbox" /><br>
    Test 2<input id="Checkbox2" type="checkbox" /><br>
    Test 3<input id="Checkbox3" type="checkbox" /><br>
</head>
<body>

</body>
</html>

<script>
    showInfo('Checkbox1');
    showInfo('Checkbox3');
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
How are you calling your function?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.