0

hello i have this table structure mentioned below

<table id="dataTable" class="center">
  <thead>
    <tr>
      <th>ID</th>
      <th>Location</th>
      <th>Type</th>
      <th>Latitiude</th>
      <th>Longitude</th>
      <th>Time Stamp</th><th >Status</th>
      <th></th></tr>
  </thead>
  <tbody>
    <tr id="saved">
      <td>10</td>
      <td>Sydney Yatch</td>
      <td>Yatch</td>
      <td>-33.848791</td>
      <td>151.218052</td>
      <td>2013-09-19 23:42:20</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=10>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>11</td>
      <td>Millers Point</td>
      <td>Point</td>
      <td>-33.858627</td>
      <td>151.204491</td>
      <td>2013-09-19 23:44:19</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=11>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>12</td>
      <td>Kot Pindi Das</td>
      <td>Restraunt</td>
      <td>31.740665</td>
      <td>74.230499</td>
      <td>2013-09-19 23:46:35</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=12>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>13</td>
      <td>Connto</td>
      <td>Island</td>
      <td>-33.848007</td>
      <td>151.171618</td>
      <td>2013-09-20 21:23:18</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=13>Delete</a> </td>
    </tr>
    <tr id="unSaved">
      <form method="get" action="db.php" ><td><input type="text" name="id" readonly value="15"/></td>
        <td> <input type="text" id="location" name="location" placeholder="Enter Location" /> </td>
        <td> <input type="text" name="type" placeholder="Enter Type" /> </td>
        <td> <input type="text" name="lat" readonly id="lat" /> </td>
        <td> <input type="text" name="long" readonly id="long" /> </td>
        <td>2013-09-21 17:35:14</td>
        <td ><input  type="text" id="status" name="isSaved" value="0" /></td>
        <td><input type="submit" value="Update" name="action" /></td>
      </form>
    </tr>
  </tbody>
</table>

now what i want is to access the value from textbox of the last row with id=isSaved by using jquery or javascript

Barmar
  • 741,623
  • 53
  • 500
  • 612
user2539602
  • 618
  • 3
  • 9
  • 18
  • 2
    id of an element must be unique in a document, you have multiple elements with the same id `saved` also the id `isSaved` is missing – Arun P Johny Sep 21 '13 at 13:38
  • 1
    There's no textbox with `id="isSaved"`. Only `name="isSaved"`, is that what you meant? – Barmar Sep 21 '13 at 13:38
  • 1
    There's also multiple `id="status"`. – Barmar Sep 21 '13 at 13:39
  • Another problem: You can't have `
    ` as a child of ``. The children of `` must be either `` or ``. http://stackoverflow.com/questions/5967564/form-inside-a-table
    – Barmar Sep 21 '13 at 13:46
  • the functionality i want is when user right click on a page it takes the coordinates and if there is a row at the end of the table whose status is not saved then the values are copied into boxes,, values are being copied but when there is no row at the bottom to fill i want to display a dialog.. – user2539602 Sep 21 '13 at 15:17
  • $("#lat").val(lat); $("#long").val(lang); var newRow = $("#dataTable > tr.unSaved").first(); //this is working fine alert(newRow.find(".status").val()); // unable to get values if(!newRow)// if never become true { $("#inputForm").dialog("open"); } else// always lend here { newRow.find("#lat").val(lat);//works newRow.find("#long").val(lang);//works newRow.find("#location").focus();//works } – user2539602 Sep 21 '13 at 15:20

3 Answers3

0

if you are using jquery and have an id its as easy as

var val = $('#isSaved').val()
Scheintod
  • 7,953
  • 9
  • 42
  • 61
0
$('input[name=isSaved]').last().val();

If in doubt, check the Jquery website for documentation

TheSunny
  • 371
  • 4
  • 14
0

I recommend:

var myValue = $('#dataTable input:last-child').val();
Cœur
  • 37,241
  • 25
  • 195
  • 267
Paul Rad
  • 4,820
  • 1
  • 22
  • 23