0

I have a table with four columns with a checkbox at the end of each row. I would like to know if there is a way of writing a jquery function that will select all the values of each row when the check box has been ticked and the submit button has been clicked.. and then pass the values to .php file to process/display. The reason i want to use the .php file is because i want to run a query to show all registered users on my system and then send the checked rows (id and name) to those users.

Sounds very complicated but i really need some help. thanks in advance.

here is the html code:

<div class="valuesOfObs">
<table>
<thead><tr><th>Valuation Name</th><th>Valuation Goal</th><th>Valuation Description</th><th>Options</th><th>Invite</th></tr></thead>

<tbody>
<?php
$sql = 'SELECT * FROM valuation';
$results = $db->query($sql);
$rows = $results->fetchAll();

foreach ($rows as $row) {
echo '<tr id="'.$row['ValuationID'].'">';
echo '<td class="crsDesc">'.$row['ValuationName'].'</td>
<td >'.$row['ValuationGoal'].'</td> 
<td >'.$row['ValuationDescription'].'</td>
<td ><a href =values.php?action=invite&id=aValue> xValue </a></td>
<td > <input type="checkbox" name="selectValue">
</td>';
echo '</tr>';
}?>
</tbody>
</table>
</div>
<input type="button" name="addrow" id="addrow" value="Add row">
<input type="button" name="inviteObs"    id="inviteObs" value="Invite Obstacle";>

Here is what I have written for the jquery so far.. I am trying to spilt the values so i can choose specifically which ones to process and then later on user the .join() method. Please help out if on the wrong track

$("input[type=checkbox], input[type=button]").on("click", function () {
$( ":checked" ).map(function() { 
return $(this).closest("tr").text();
}).split("</td><td>");

var compName = $("#id").val();

$.ajax({
url : "inviteObstacles.php",
type : "POST",
data : {"compID" : compName},
success : function (n){
//do something
}
})

});
2
  • I can already say you have quotation issues in the link in your echo statement. Commented Nov 5, 2013 at 5:26
  • thanks for spotting! will clear these up.. Commented Nov 5, 2013 at 5:44

1 Answer 1

1

Use .map() function to pass each element in the current matched set through a function, which will produce new jQuery object containing the return values.

Here is a code:

$("input[type=checkbox]").on("click", function () {
$( ":checked" ).map(function() { return $(this).closest("tr").text();
}).get().join();   //Use join to split the fetched row using separator "," on server-side
});

Demo: http://jsfiddle.net/tSeau/1/

Sign up to request clarification or add additional context in comments.

4 Comments

brilliant!! could i run a check to see if the inviteObs button have also been clicked, then after that will the map function be called? also could you pls give me some pointer on how to link this with my .php file as i would like to display the clicked rows with a users table. thanks
Check the updated fiddle..To connect it to .php file use jquery ajax.
sorry to bother you again.. but do i use the split on my php file and then join in the jquery code? im a bit confused..
Split data on your php file using explode function.In that way you can fetch each record using for each loop..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.