- Home
- Forum
- ASP.NET Core - EJ 2
- Set Checked value in code?
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>
<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;
}
switch (role) {
case "Emp":
var rb = document.getElementById('rdEmp').ej2_instances[0];
rb.checked=true; //Does not work..
break;
}
}
Thanks..
SIGN IN To post a reply.
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.
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 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
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.
Regards,
Silambarasan
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.
Regards,
Silambarasan
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
ML Michael Lambert
- Mar 3, 2019 09:46 PM UTC
- Mar 8, 2019 04:24 AM UTC