ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How can I get a checkbox's value in jQuery?

user-image
تم إضافة السؤال من قبل Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
تاريخ النشر: 2013/04/08
Hazem Salama
من قبل Hazem Salama , Senior Member of Technical Staff , Verizon Communications

If you mean the value that you have in the value attribute of the checkbox then you can use this //Assuming your check box id is chkBox $('#chkBox').val(); If you mean the state, whether checked or not, you can use plain old javascript document.getElementById('chkBox').checked; // will return false or true depending on the state // OR in jquery $('#chkBox').is(':checked');

Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

There are two parts of the question I guess.
They are: 1.
You want to get checkbox value regardless of whether it is checked or not? 2.
You want to get THE "Checked" checkbox value.
Answers: 1.
You can get checkbox value: $("#checkbox_id").val(); $(".checkbox_class").val(); // this is return in array if particular class is applied on many other fields or checkbox.
2.
You can get Checed checkbox value: if( $("#checkbox_id").attr("checked") ) { $("#checkbox_id").val(); }

Faizan Ahmad
من قبل Faizan Ahmad , Software Engineer , cardekho.com

on check box change event $('#checkboxid').change(function(){ if($('#checkboxid').is('checked')) { var val = $('#checkboxid').val(); console.log(val); } });

مستخدم محذوف‎
من قبل مستخدم محذوف‎

function checkboxValues() { var values = []; $('#checkbox :checked').each(function() { values.push($(this).val()); }); console.log(values); } don't forget to enable firebug to see the results .

Panneer selvam xavier
من قبل Panneer selvam xavier , Supply Chain Analyst / Trainer , Infonet

$("input[type='checkbox']").val(); Or if you have set a class or id for it, you can: $('#check_id').val(); $('.check_class').val(); Also you can check whether it is checked or not like: if ($('#check_id').is(":checked")) { // it is checked }

مستخدم محذوف‎
من قبل مستخدم محذوف‎

$("#theChk").prop("checked") 

$("#theChk").attr("checked") 

$("#theChk").val()

Besim Dauti
من قبل Besim Dauti , Ceo / Front End Developer , Nunforest

if ($('#check_id').is(":checked")) { // it is checked }

المزيد من الأسئلة المماثلة