What I want to do is, return the value checked on each checkbox on a modal-box to a text-box. This question is quite similar to this one, but the aim of the question is different. So please take a look both of them. 🙂
I’ve the code to initialize the modal-box:
<script>
var grid_modal_options = {
height: 'auto',
width: '80%',
modal: true
};
function showProductsModalBox() {
$("#products_modal_box").dialog(grid_modal_options);
$("#products_modal_box").parent().appendTo('form:first');
}
</script>
<div id="products_modal_box" title="Products" style="display: none;">
<div class="in">
<div class="grid-12-12">
<form id="products_modal_box_form" action="#" method="post">
<a href=\"javascript:;\" onclick=\"$('#products_id_textbox').val(\"input[name='checkedID[]']:checked\");$('#products_modal_box').dialog('close')();\">Submit</a>
<table>
<thead>
<tr>
<th> </th>
<th>Product</th>
</tr>
</thead>
<!-- Query for read mysql goes here (I skipped this line because it's not the main thing I'm gonna ask since it's run well) /-->
<tbody>
<?php
//read the results
while($fetch = mysqli_fetch_array($r)) {
print "<tr>";
print " <td><input type='checkbox' name='checkedID' value='" . $fetch[0] . "' /></td>"; //--> How to get the value of $fetch[0], collect it and return to a textbox?
print " <td>" . $fetch[0] . "</td>"; //$fetch[0] == Product ID
print "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
As you see above, I am trying to use pseudo-selector function: input[name='checkedID[]']:checked but failed to return the value. Or there is something I missed for the code?
And here is the textbox for return the value checked on the modal-box:
<input type='text' id='products_id_textbox' name='products_id_textbox' />
<a href='#' onclick='showProductsModalBox(); return false;'>Choose products</a>
The code able is to show the modal-box. But how to return the “Product” chosen from each textbox by the user to the textbox products_id_textbox? Thanks.
The problem solved with this code:
and a modification on the button that just for closing the modal-box:
That function called :checked Selector.
Thank you very much and hope helps… 🙂