Hi,

I have a page with multiple tables, and need to get the index value of
a cell with a price which i click on, so i can extract the relevent
quantity within the row above, i've tried using the index() function
but to no avail!

also, I wish to extract the content of the previous h2 header, i'm not
sure if closest('h2') is the best way to do it, but it also doesn't
work, could someone please tell me how to do this?

Please see below for the code (note that there is roughly about ten
tables to which i've cut down to two for here, also I CANNOT change
the tables i.e. add id or classes anywhere, so the tables have to stay
the way they are, I just need to get some jquery code to work around
this and extract the relevant data).

So a brief run down of what i need to do :

1) get the quantity above the price that is clicked
2) get the content of the heading above the relevant table

THE CODE :

<h2 class="sublisting">First Item Named here</h2>
<p>information goes here</p>
<table class="price_table">
  <tr>
    <th> Quantity</th>
    <th> 1000 </th>
    <th> 5000 </th>
    <th> 10,000 </th>
    <th> 15,000 </th>
    <th> 20,000 </th>
  </tr>
  <tr>
    <td> Price </td>
    <td><strong>£400</strong><br />
      <span class="each_item">40p each</span></td>
    <td><strong>£1650</strong><br />
      <span class="each_item">33p each</span></td>
    <td><strong>£3200</strong><br />
      <span class="each_item">32p each</span></td>
    <td><strong>£4800</strong><br />
      <span class="each_item">32p each</span></td>
    <td><strong>£6200</strong><br />
      <span class="each_item">31p each</span></td>
  </tr>
</table>
<h2 class="sublisting">second Item Named here</h2>
<p>information goes here</p>
<table class="price_table">
  <tr>
    <th> Quantity</th>
    <th> 1000 </th>
    <th> 5000 </th>
    <th> 10,000 </th>
    <th> 15,000 </th>
    <th> 20,000 </th>
  </tr>
  <tr>
    <td> Price </td>
    <td><strong>£400</strong><br />
      <span class="each_item">40p each</span></td>
    <td><strong>£1650</strong><br />
      <span class="each_item">33p each</span></td>
    <td><strong>£3200</strong><br />
      <span class="each_item">32p each</span></td>
    <td><strong>£4800</strong><br />
      <span class="each_item">32p each</span></td>
    <td><strong>£6200</strong><br />
      <span class="each_item">31p each</span></td>
  </tr>
</table>
<script type="text/javascript">
//<![CDATA[
  $('.each_item').parent().click( function() {
        var indexvar = $(this).parent().index(this); /********* NOT WORKING
************/
        var headerval = $(this).closest('h2').text(); /********** ALSO NOT
WORKING **********/
        var quantity = $(tbodyvar).children('tr').children('th').eq
(indexvar).text();
        alert('Requested ' + quantity + ' of ' + headerval);
  });

//]]>
</script>

Reply via email to