*Please help me, I am just a beginner
I have input fields above this foreach block, but this is the focus of my concern.
foreach ($display_eqp as $value){
$eqpid = $value['Eqp_ID'];
$available = $value['OnHand'];
echo "<tr>";
echo "<td class='center'><input type='checkbox' class='checkbox'
name='request-equipment[". $eqpid ."]' id='". $eqpid ."-checkbox'
value=" . $eqpid . " onchange='enableQtyTxtbox(this.value)' disabled></td>";
echo "<td class='center'><input type='text' class='form-control'
style='width: 60px;' name='available-" . $eqpid . "' id='available-" . $eqpid . "'
value=" . $available . " readonly></td>";
echo "<td class='center'><input type='text' placeholder='...' class='form-control'
style='width: 60px;' onchange='checkQty(this.value, ". $eqpid .")'
name='request-quantity[". $eqpid ."]' id='". $eqpid ."' disabled='true'/></td>";
echo "</tr>";
I have 2 javascripts.
1st is this one, where in when an individual checkbox checked state is change, it enabled/disabled and clears the corresponding textbox and enables/disables the submit button also. This is working, that is for individual only and this is triggered by ticking the checkbox.
function enableQtyTxtbox(val) {
var checkbox = document.getElementById(val + "-checkbox");
var textbox = document.getElementById(val);
var submitbtn = $("input[type='submit']");
textbox.disabled = !(checkbox.checked);
if (checkbox.checked) {
submitbtn.attr("disabled", true);
}
else{
textbox.value = "";
}
}
now my concern is this 2nd script.
function checkValue(id){
var value = document.getElementById(id).value;
var checkboxes = $("input[type='checkbox']");
// this does not work: var textbox= $("input[name='request-quantity[]']"); ????
if (value == "") {
checkboxes.attr("disabled", true); //this works
checkboxes.checked = false; // this does not work, please if you could answer this one
// for me also, it would be a big help.
// clear textbox
// disable textbox
}
else{
checkGroup();
}
}
What I want to do here is to get all the textbox named request-quantity (which is an array with assigned index) and clear and disable it just like the first script. But I dont know how to access the element.
$('input[name^="request-quantity"]')
is the selector to get the items that have a name starting with 'request-quantity'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.