admin管理员组文章数量:1415446
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,
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,
Share Improve this question edited Jul 21, 2016 at 9:22 sebaferreras 44.7k11 gold badges119 silver badges137 bronze badges asked Jul 21, 2016 at 8:43 rjcoderjcode 1,3471 gold badge27 silver badges64 bronze badges1 Answer
Reset to default 8You 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;
本文标签: javascriptPass value of checkbox to variable only if it checkedStack Overflow
版权声明:本文标题:javascript - Pass value of checkbox to variable only if it checked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745160192a2645405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论