admin管理员组文章数量:1025260
I have a table with text data but in one cell I have a checkbox. I can extract data from td, but I can't figure out how to extract the checkbox value
Here's what I've tried (see attached picture!)
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
I have a table with text data but in one cell I have a checkbox. I can extract data from td, but I can't figure out how to extract the checkbox value
Here's what I've tried (see attached picture!)
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
https://drive.google./file/d/0BxKM9sqBGY28cXp5ZzVCc0dRc28/view?usp=sharing
Share Improve this question edited May 27, 2015 at 17:03 Samurai 3,7295 gold badges28 silver badges40 bronze badges asked May 27, 2015 at 17:01 Slavik OstapenkoSlavik Ostapenko 1131 gold badge3 silver badges10 bronze badges 1- possible duplicate of how to get the value of a checked checkbox – Seth McClaine Commented May 27, 2015 at 17:04
6 Answers
Reset to default 2$('#tableData tbody tr:eq('+row+')').find('td:eq(8) input').is(':checked')
Checkbox has 2 states. Checked and unchecked.
To get the value use the .prop('value') - please see my JSFiddle at the bottom. (I also updated the example(s))
I hope you are properly setting checked value on the control (from your code it is not clear if you're trying to set the value to something and expecting to see a checked checkbox or you're properly setting "checked" property.
<input type="checkbox" id="myCheckboxId" value="0" checked>
In jquery use the selector to find the checkbox. Please search SO since there are so many examples. Looping with "row" as counter is not the best way, use .each on the table to look for rows with checked checkboxes.
Even with what you have add and ID to your control (checkbox):
var isChecked = $('#tableData tbody tr:eq('+row+')').find('myCheckboxId').is(':checked');
Or:
var isChecked = $('#tableData tbody tr:eq('+row+') input:checkbox').is(':checked');
var checkBoxValue = $('#tableData tbody tr:eq('+row+') input:checkbox').prop('value');
http://api.jquery./checkbox-selector/ try there first.
JSFiddle Demo
You can do this way:
$('#tableData tbody tr:eq('+row+') td:eq(8) input').val()
You're targeting the td
element, instead the input
, no? Try:
$('#tableData tbody tr:eq('+row+') td:eq(8) input').val()
You could query for the checkbox itself. (Even better, give the checkbox a name or an ID and query for that.)
alert($('input[type=checkbox]').val());
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table><tr><td><input type="checkbox" value="99"></td></tr></table>
You are not specifying the checkbox at all in your query.
Try changing:
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
To:
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).find('checkbox').val();
I have a table with text data but in one cell I have a checkbox. I can extract data from td, but I can't figure out how to extract the checkbox value
Here's what I've tried (see attached picture!)
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
I have a table with text data but in one cell I have a checkbox. I can extract data from td, but I can't figure out how to extract the checkbox value
Here's what I've tried (see attached picture!)
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
https://drive.google./file/d/0BxKM9sqBGY28cXp5ZzVCc0dRc28/view?usp=sharing
Share Improve this question edited May 27, 2015 at 17:03 Samurai 3,7295 gold badges28 silver badges40 bronze badges asked May 27, 2015 at 17:01 Slavik OstapenkoSlavik Ostapenko 1131 gold badge3 silver badges10 bronze badges 1- possible duplicate of how to get the value of a checked checkbox – Seth McClaine Commented May 27, 2015 at 17:04
6 Answers
Reset to default 2$('#tableData tbody tr:eq('+row+')').find('td:eq(8) input').is(':checked')
Checkbox has 2 states. Checked and unchecked.
To get the value use the .prop('value') - please see my JSFiddle at the bottom. (I also updated the example(s))
I hope you are properly setting checked value on the control (from your code it is not clear if you're trying to set the value to something and expecting to see a checked checkbox or you're properly setting "checked" property.
<input type="checkbox" id="myCheckboxId" value="0" checked>
In jquery use the selector to find the checkbox. Please search SO since there are so many examples. Looping with "row" as counter is not the best way, use .each on the table to look for rows with checked checkboxes.
Even with what you have add and ID to your control (checkbox):
var isChecked = $('#tableData tbody tr:eq('+row+')').find('myCheckboxId').is(':checked');
Or:
var isChecked = $('#tableData tbody tr:eq('+row+') input:checkbox').is(':checked');
var checkBoxValue = $('#tableData tbody tr:eq('+row+') input:checkbox').prop('value');
http://api.jquery./checkbox-selector/ try there first.
JSFiddle Demo
You can do this way:
$('#tableData tbody tr:eq('+row+') td:eq(8) input').val()
You're targeting the td
element, instead the input
, no? Try:
$('#tableData tbody tr:eq('+row+') td:eq(8) input').val()
You could query for the checkbox itself. (Even better, give the checkbox a name or an ID and query for that.)
alert($('input[type=checkbox]').val());
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table><tr><td><input type="checkbox" value="99"></td></tr></table>
You are not specifying the checkbox at all in your query.
Try changing:
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).value
To:
$('#tableData tbody tr:eq('+row+')').find('td:eq(8)').eq(0).find('checkbox').val();
本文标签: jqueryHow to get a value of a CheckBox from td (table)JavaScriptStack Overflow
版权声明:本文标题:jquery - How to get a value of a CheckBox from td (table), JavaScript? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1744383830a2094466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论