jquery - HTML check box row select code -
i need please.
below code html table.
it has multiple checkboxes.
what want once "hold"check-box clicked, want grab shipment number field selected row can ajax using number.
can please me out
<table id='consignment_list' class="consignment_list_tbl"> <colgroup width='20'> </colgroup> <?php if ($user->getuseraccount() == "") echo "<colgroup width='30'> </colgroup>"; ?> <!-- table head --> <thead> <tr> <th>select <input type='checkbox' name='checkall' onclick='checkedall(deleteconsignments1);'> </th> <th>status</th> <?php if ($user->getuseraccount() == "") echo "<th>account</th>"; ?> <th>packages</th> <th>hawb</th> <th>awb</th> <th>consignee name</th> <th>city</th> <th>country</th> <th>weight</th> <th>no of pieces</th> <th>piece id</th> <th>hold</th> <th>heavy weight</th> </tr> </thead> <!-- table foot --> <tfoot> <tr> <td> </td> <?php if ($user->getuseraccount() == "") echo "<td> </td>"; ?> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </tfoot> <!-- table body --> <tbody> <?php foreach ($consignment_array $ct_idx => $consignment) { foreach ($consignment->getparcels(true) $parcel) { if($parcel->getprocessed()==1) { continue; } $status = $consignment->getstatus(); $id= $consignment->getid(); ?> <tr style="background-color: red;color: black;" id="<?php echo $parcel- >getlicenceplate()?>" name="<?php echo $consignment->getawb()?>"> <td id="c"> <input type=checkbox id= "deleteconsignments1" name="deleteconsignments[]" onclick="row_color(this)" value="<?php $consignment->getid()?> " /> </td> <td><?php echo consignment::statetext($status); ?></td> <?php if ($user->getuseraccount() == "") echo "<td>" . $consignment->getaccount() . "</td>"; ?> <td class="colpieces"><?php echo $consignment->getnumberpieces(); ?></td> <td><a href='../main/consignment_edit.php?from=client&id=<?php echo $consignment->getid(); ?>' style="color: white;"> <?php echo $consignment->gethawb(); ?></a></td> <td><?php echo $consignment->getawb(); ?></td> <td><?php echo $consignment->getcontact(); ?></td> <td><?php echo $consignment->getcity(); ?></td> <td><?php echo $consignment->getcountry();; ?></td> <td><?php echo $consignment->getweight(); ?></td> <td><?php echo $consignment->getnumberpieces(); ?> <td><?php echo $parcel->getlicenceplate(); ?></td> <td><input type=checkbox onclick="row_colorhold(this)" name="hold[]" id="hold1" value="<?php echo $consignment->getid(); ?>" ></td> <td><input type='checkbox' name='heavyweight[]' id="heavyweight" value="<? php echo $consignment->getid(); ?>"></td> </td> </tr> <?php } } ?> </tbody> </table>
here is: https://jsfiddle.net/y0vhw7cu/
note includes jquery tagged question it.
it's simple:
a class "hold" has been added checkbox:
<input class="hold" type=checkbox onclick="row_colorhold(this)" name="hold[]" id="hold1" value="<?php echo $consignment->getid(); ?>" > and this:
// make sure document (your markup) ready $(document).ready(function() { // detect click of element has .hold classs $(".hold").click(function() { // when happens, assign value of clicked element variable var value = $(this).val(); // whatever want variable:) alert(value); }); }); if want more stuff elements, can wrapped in single $(document).ready
edit: example of course show <?php echo $consignment->getid(); ?> when click it, when apply actual code, php dynamically replace appropriate value.
edit 2: https://jsfiddle.net/xtr2peu3/
as per comment, here little bit different. we're attaching .hold class <td> contains "hold" checkbox:
<td class="hold"> <input type=checkbox onclick="row_colorhold(this)" name="hold[]" id="hold1" value="<?php echo $consignment->getid(); ?>" ></td> then attach click event handler it, , when gets clicked, grab textual content of previous element:
$(".hold").click(function() { var value = $(this).prev().text(); alert(value); });
Comments
Post a Comment