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.
Unfortunately, activation email could not send to your email. Please try again.

Set and Get CheckBox value programmatically with Jquery

Thread ID:

Created:

Updated:

Platform:

Replies:

119764 Jul 28,2015 06:15 AM Jul 29,2015 07:38 AM JavaScript 2
loading
Tags: ejCheckBox
Carlo
Asked On July 28, 2015 06:15 AM

With other syncfusion controls, when I have to assign them a value, when the view is first loaded I do something like this:

(this is an example with control maskedit)

$('#Surname').ejMaskEdit({
            value:'@Model.Person_Surname'
        });

-> this approach doesn't work with checkbox:

form.find('#CheckBox').ejCheckBox({
            value: '@Model.Interaction_Flag'
                });

..and this doesn't work either:

form.find('#CheckBox').ejCheckBox({
            checked: '@Model.Interaction_Flag'
                });

Also, about recovering a value (for example to prepare the JSON for an ajax call), I usually do something like this:

Person_Surname: $('#Surname').val()

with checkboxes I have tried the following, which doesn't work:

Interaction_Flag: $('#CustomCheck').val()

..and this doesn't work either:

Interaction_Flag: form.find('#CustomCheck').checked()

More generally speaking, what is the general best approach to handle these GET / SET scenarios with syncfusion controls? Thanks

Carlo
Replied On July 29, 2015 04:10 AM

Just a quick upgrade; at the moment I solved the issue doing the following - very ugly - solution:

  • I declare the control like this: (1)
<input type='checkbox' id='CheckBox' />
  • Then I set it to be an ejCheckBox and recover the value from the model this way: (2)

form.find('#CheckBox').ejCheckBox({
            checked: @Json.Encode(@Model.Interaction_Flag),
        });

  • Finally, when I need to get the checkbox value (to prepare a JSON), I do this (which is the ugly part): (3)
form.find('#CheckBox').data('ejCheckBox')._isChecked

Regarding this last part (3), I also tried to do this:

form.find('#CheckBox').prop('checked') 

but that fails to get the correct checkbox value if the checked state was set to true by the code at (2) and not by the user. I'd really like to know if I'm following the best approach to handle the scenario, especially regarding the code at (3), which seems to be very ugly (isn't _isChecked a private property after all?)

Sasikala Nagarajan [Syncfusion]
Replied On July 29, 2015 07:38 AM

Hi Carlo,

Thanks for using Syncfusion products,

We can get and set the check box checked state using checked property(Boolean type – true/false).

Please refer the below code snippet to set the value to checkbox at that time of initialization.
[html]
<input type="checkbox" id="check1" />

[script]
$("#check1").ejCheckBox({checked:true});



We can get the check box’s checked state from object of the checkbox. Please refer the below code snippet to get the checked state of ejcheckbox
[script]
obj = $("#check1").ejCheckBox('instance');
obj.option("checked");


Please refer the below link to know more about possible methods to get and set the properties of ej controls

http://helpjs.syncfusion.com/js/api-configuration

We have prepared the simple sample based on this. Please refer the below link
http://jsplayground.syncfusion.com/31f4zqth

Please check with given links and let us know if you have further queries,

Regards,

Sasikala Nagarajan

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.

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.

;