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>
    </div>

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

Thanks..


5 Replies

SI Silambarasan I Syncfusion Team March 5, 2019 09:03 PM

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. 
 
Sample: 
 
CODE SNIPPET: 
 
<div class="row"> 
    <ejs-radiobutton id="rdEmp" label="Officer" name="rdRole" value="Emp"></ejs-radiobutton> 
    //... 
</div> 
<ejs-button id="btn" content="Select" onClick="btnClick()"></ejs-button> 
 
<script> 
 
    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; 
 
    } 
 
</script 
 
 
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. 
 
Regards, 
Silambarasan 



ML Michael Lambert March 6, 2019 03:19 PM

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?

Thanks,
Mike


SI Silambarasan I Syncfusion Team March 7, 2019 07:39 AM

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. 
 
Regards, 
Silambarasan 



ML Michael Lambert March 7, 2019 12:18 PM

Thanks Silambarasan.


SI Silambarasan I Syncfusion Team March 7, 2019 11:24 PM

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


Loader.
Live Chat Icon For mobile
Up arrow icon