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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set Checked value in code?

Thread ID:

Created:

Updated:

Platform:

Replies:

143067 Mar 3,2019 09:46 PM UTC Mar 8,2019 04:24 AM UTC ASP.NET Core - EJ 2 5
loading
Tags: Radio Button
Michael Lambert
Asked On March 3, 2019 09:46 PM UTC

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..


Silambarasan I [Syncfusion]
Replied On 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. 
 
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 


Michael Lambert
Replied On 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?

Thanks,
Mike

Silambarasan I [Syncfusion]
Replied On 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. 
 
Regards, 
Silambarasan 


Michael Lambert
Replied On March 7, 2019 05:18 PM UTC

Thanks Silambarasan.

Silambarasan I [Syncfusion]
Replied On 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. 
 
Regards, 
Silambarasan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;