0

I am using iCheck for checkbox and below checkbox selection html,

<input type="checkbox" name="allDay" id="allDay" class="icheck" data-checkbox="icheckbox_minimal-red" value="true"> All day event</label>

I am submitting form using Ajax, but not with .serialize() function, i am taking individual form entry as .val() and then do some manipulation on entry and then pass as variable in form ajax data,

Now i want to pass value for checkbox if its selected, otherwise it should not pass any value,

I have below code for taking value for variable,

allDay = $('#allDay').val();

But with this, it always pass value = true even if its checked or unchecked.

How can i pass value of checkbox to variable only if it checked?

Thanks,

1 Answer 1

8

You can use :checked selector:

allDay = $('#allDay:checked').val();

or instead you can use .is() too if you are looking for default value:

allDay = $('#allDay').is(':checked'); // "true" if checked | "false" on unchecked;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.