Becca
Becca

Reputation: 39

Get value using JQuery?

Hi I am trying to get a value of each name displayed in a table. I want to have a button beside each name as a 'favourite' button. Each name displayed has a unique number ID, and i was wondering how am i able to get this?

at the moment, when i click the fav button all that appears is:
.$dbRow[

Can someone help?

$i = 0;
while($i < $counter) {
  echo '<tr>';
  if(isset($arr['nameB'][$i])) {
    echo ''.$arr['nameB'][$i].'value=".$arr["nameB"].">Add</button></td>';
  }else{

<script>

$(document).ready(function() {
  $(".add").click(function(e) {
    e.preventDefault();
    var id = $(this).prop('id');  
  });
});

</script>

Upvotes: 1

Views: 41

Answers (1)

Jay Blanchard
Jay Blanchard

Reputation: 34426

Your concatenation is off in the following line:

echo '<td>'.$arr['BoysName'][$i].'<button class="favourites" id=".$dbRow["nameID"]. value=".$arr["BoysName"].">Favourite</button></td>'

It should be

echo '<td>'. $arr['BoysName'][$i] . '<button class="favourites" id="' . $dbRow["nameID"] . '" value="' . $arr["BoysName"] . '">Favourite</button></td>'

Upvotes: 3

Related Questions