We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set Checked value in code?

I'm trying to set the Checked value of a ejs-radiobutton in a function and cannot figure it out..

    <div class="row">
        <ejs-radiobutton id="rdEmp" label="Officer" name="rdRole" value="Emp"></ejs-radiobutton>
        <ejs-radiobutton id="rdSupervisor" label="Supervisor" name="rdRole" value="Admin"></ejs-radiobutton>
        <ejs-radiobutton id="rdTSAdmin" label="Time Sheet Admin" name="rdRole" value="Admin"></ejs-radiobutton>
        <ejs-radiobutton id="rdAdmin" label="Administator" name="rdRole" value="Admin"></ejs-radiobutton>

    function SelectRole(role) {
        switch (role) {
            case "Emp":
                var rb = document.getElementById('rdEmp').ej2_instances[0];
                rb.checked=true;   //Does not work..


5 Replies

SI Silambarasan I Syncfusion Team March 6, 2019 02:03 AM UTC

HI Michael, 
Thank you for contacting Syncfusion support. 
We have checked your reported issue by preparing sample in our latest version and the RadioButton checked property is working properly in our end. Please find the below sample for your reference. 
<div class="row"> 
    <ejs-radiobutton id="rdEmp" label="Officer" name="rdRole" value="Emp"></ejs-radiobutton> 
<ejs-button id="btn" content="Select" onClick="btnClick()"></ejs-button> 
    function btnClick() { 
        //Direct access of RadioButton instance. 
        var rb = document.getElementById('rdEmp').ej2_instances[0]; 
        rb.checked = true; 
        //Recommended way to access instance. 
        //var rbObj = ej.base.getComponent(document.getElementById("rdEmp"), 'radio'); 
        //rbObj.checked = true; 
Could you please check & replicate your issue in the above sample and send back to us with more information so that we could able to sort out the cause of this issue and provide you a better solution quickly? The information provided would be great help for us to proceed further. 

ML Michael Lambert March 6, 2019 08:19 PM UTC

Hi Silambarasan,
That did work.  Thanks!  For my future knowledge, how did you know to use 'radio' in rbObj = ej.base.getComponent(document.getElementById("rdEmp"), 'radio');
Why wouldn't it be ejs-radiobutton .  Can you point to the documentation that describes this?


SI Silambarasan I Syncfusion Team March 7, 2019 12:39 PM UTC

Hi Michael, 
Sorry for the inconvenience. Please ignore the provided solution with getComponent() method in our last update. 
We would like to suggest you to pass the component as second argument in ‘getComponent()’ method to get the instance. Please refer the below standard way to access the component instance. 
var rbObj = ej.base.getComponent(document.getElementById("rdEmp"), ej.buttons.RadioButton); 
rbObj.checked = true; 
We will update our documentation about this standard way to access the component and it will be available in our upcoming releases. 

ML Michael Lambert March 7, 2019 05:18 PM UTC

Thanks Silambarasan.

SI Silambarasan I Syncfusion Team March 8, 2019 04:24 AM UTC

Hi Michael, 
Most welcome. Please get back to us if you need any further assistance. We are happy to help you out. 

Live Chat Icon For mobile
Up arrow icon