1

i have requirement where i need to check if apex:inputCheckbox is checked, and if it isn't then raise an alert saying that its not checked.

 <apex:inputCheckbox value="{!check}"/>

I am raising the alert from a java script. i am using actionfunction to call a apex method after the alert is raised.

What i need is a way to check if the checkbox is checked or not in javascript

Thanks

Prady

1 Answer 1

6

You can just give it an id, then use document.getElementById() to grab it:

<apex:inputCheckbox id="theCheckBox" value="{!Contact.Some_Checkbox__c}" onClick="alert('checked? ' + document.getElementById('{!$Component.theCheckBox}').checked);"/>

Note that if it's inside other elements with you may need to drill down to it, so if it was inside an <apex:pageBlockSection> with id="theSection" then you'd need:

document.getElementById('{!$Component.theSection.theCheckBox}');

Whether you need to do this or not depends on where your javascript is in the page with relation to the checkbox. Good luck!

Sign up to request clarification or add additional context in comments.

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.