Expand|Select|Wrap|Line Numbers
- $(document).ready(function() {
- $("#product_select > option").click(function () {
- var selectvalue = $('#product_select').val();
- $.post("<?php echo SITE_URL; ?>sale/ajax",
- { id: selectvalue },
- function(return_id)
- {
- var return_array = return_id.split(",");
- $("#price").val(return_array[0]);
- if (return_array[1] == 1) {
- $('#duration').removeAttr("disabled");
- $('#duration').attr('enabled', 'enabled');
- $('#duration').val('0');
- } else {
- $('#duration').removeAttr("enabled");
- $('#duration').attr('disabled', 'disabled');
- $('#duration').val('0');
- }
- });
- });
- });
- </script>
Expand|Select|Wrap|Line Numbers
- <div id="main">
- <h2><i><u>Order Header Details</u></i></h2><br />
- <table id="sale" border='1' style="border-style: outset; empty-cells: show">
- <tr>
- <th>Order No</th>
- <th>Date</th>
- <th>Account</th>
- <th>Amount</th>
- <th>Payment Method</th>
- <th>Sales Rep</th>
- </tr>
- <tr>
- <td><strong><?php echo $order->order_id; ?></strong></td>
- <td><?php echo $order->date_added; ?></td>
- <td><?php echo $order->company_name; ?></td>
- <td>£<?php echo number_format($order->sales_total,2) ?></td>
- <td><?php echo $order->payment_option; ?></td>
- <td><?php echo $order->rep_name; ?></td>
- </tr>
- </table>
- <h2><i><u>Order Line Details</u></i></h2><br />
- <table id="basket" border='1' style="border-style: outset; empty-cells: show">
- <tr>
- <th>Item type</th>
- <th>Price (£)</th>
- <th>per</th>
- <th>Duration</th>
- <th>Update</th>
- <th>Delete</th>
- </tr>
- <?php
- //$i = 0;
- foreach ($basket as $basket) {
- ?>
- <tbody>
- <tr class="line edit_item">
- <td class="product">
- <select class="product_select" id="product_select<?php echo $i; ?>" name="product">
- <?php foreach ($products as $product) { ?>
- <option value="<?php echo $product->product_id; ?>" <?php if ($product->product_id == $basket->product_id) { echo 'selected="selected"'; } ?>><?php echo $product->product_name; ?></option>
- <?php } ?>
- </select>
- </td>
- <td class="price">
- <input name="price" class="price" id="price<?php echo $i; ?>" type="text" value="<?php echo $basket->unit_price; ?>" size="5" />
- </td>
- <td class="per"> </td>
- <td class="duration">
- <select name="duration" class="duration id="duration<?php echo $i; ?>">
- <option value="0">(Select)</option>
- <option value="1">1 Month</option>
- <option value="3">3 Months</option>
- <option value="6">6 Months</option>
- <option value="12">1 Year</option>
- </select>
- </td>
- <td class="controls"><button type="button" id="update">Update</button></td>
- <td class="controls"><button type="button" id="delete">Delete</button></td>
- </tr>
- <?php
- //$i++;
- } ?>
- </tbody>
- </table>
- </div>
My theory for the code is that i require the row.index of each order line and passing that value through to the javascript however i have tried many times to find and get the current row.index syntax to work. I don't know what i am doing wrong. Here is the code i have been looking at;
Expand|Select|Wrap|Line Numbers
- onload = function() {
- if (!document.getElementsByTagName || !document.createTextNode) return;
- var rows = document.getElementById('my_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
- for (i = 0; i < rows.length; i++) {
- rows[i].onclick = function() {
- alert(this.rowIndex + 1);
- }
- }
- }
Any advice or views on how or what i should do to get this code working would be greatly appreciated. Thanks in advance.