[英]Get the values of column if checkbox/radio box is checked
I was wondering how to get the values in a certain column if the checkbox or radio button on that particular row is checked. 我想知道如果选中了特定行上的复选框或单选按钮,则如何获取特定列中的值。 I've already started and came up with this:
我已经开始并提出了以下建议:
<script>
var Step = <?php echo $_SESSION['Step'] ?>;
if(Step == 3 || Step == 4 ) { setInterval(ScriptUpdate, 1000); }
function ScriptUpdate()
{
if(Step == 3)
{
var checked = $("input:checkbox:checked").length;
var radioButtonSelectedCount = $(document.querySelectorAll('input[type=radio]:checked')).parent().filter(function() {return $(this).text().trim()=="Yes"}).length;
var Counter = checked + radioButtonSelectedCount;
$('#ES3I').text(Counter + ' Items');
var price = 0;
$("#TextBookTB tr:gt(0) td:nth-child(6)").each(function(td){
var content = $(this).text();
if($.isNumeric(content)) {
price = price + Number(content);
console.log(price);
}
});
$("#ES3P").text(price);
}
}
</script>
The goal is that: when user checks the check box or answered 'yes' in the radio button it is the only time it will count the value. 目的是:当用户选中该复选框或在单选按钮中回答“是”时,它将是唯一一次计算该值的时间。 Apologies, I am really bad at jquery/javascript.
抱歉,我对jquery / javascript真的很不好。
EDIT: html code as requested. 编辑:html代码按要求。 The current output of the timer takes all of the values in all rows of that particular column.
计时器的当前输出采用该特定列的所有行中的所有值。
<label class="radio-inline">
<input form="ES3S" type="radio" name="Textbook'.$i.'" value="'.$Result[$i]['ID'].'"> Yes
</label>
<label class="radio-inline">
<input form="ES3S" type="radio" name="Textbook'.$i.'" value="-1">No
</label>
<span class="d-inline-block" data-toggle="popover" title="Error" data-content="This book is required by the school. If you want to cancel this out, proceed to the principals office with the book for review." data-trigger="hover">
<input form="ES3S" required checked onclick="return false;" type="checkbox" value="'.$Result[$i]['ID'].'" name="Textbook'.$i.'">
</span>
try this if you are using table 如果使用表,请尝试此
var count = 0;
$('#TABLEID').find('tr').each(function () {
var tableRow = $(this);
if (tableRow.find('input[type="checkbox"]').is(':checked')) {
count += 1;
}
});
when user checks the check box or answered 'yes' in the radio button it is the only time it will count the value
当用户选中该复选框或在单选按钮中回答“是”时,它将是唯一一次计算该值的时间
$(function() { var selector = 'input[name^="Textbook"]'; $(selector).on('click', function() { var checked = $(selector + ':checked').map(function() { return { 'type': this.type, 'value': this.value }; }).get().filter(function(o) { return '-1' !== o.value; // skip if value = -1(No) }); console.log('checked inputs', checked); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <label><input type="radio" name="Textbook1" value="1"/>Yes</label> <label><input type="radio" name="Textbook1" value="-1"/>No</label> <input type="checkbox" name="Textbook1" value="1" /> </div> <div> <label><input type="radio" name="Textbook2" value="2"/>Yes</label> <label><input type="radio" name="Textbook2" value="-1"/>No</label> <input type="checkbox" name="Textbook2" value="2" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.