Solved

how to grab selcted values from check boxes with Jquery, process array with php and make mysql query

Posted on 2011-02-17
5
256 Views
Last Modified: 2014-06-01
Hi All,
I have a web search for where user searches for plants at http://www.rootsnantucket.com/duplicate-of-the-catalog.html 

when user performs a search, jquery passes the search term to a page that then refreshes the table with the new values.  The new table has a new column labeled 'print me'.  User clicks on plants interested in printing and the hits "print these plants".  I want the values of the checkboxes to be passed to a second page attached below that will then run a select query and then create a new table with new plants.

I tried searching for "astil" which pulls up a bunch of plants.  I check some plants and then click print and an empty table gets returned to the viewer.  The values aren't being passed to the query, and are not being output.  

Any guidance or links to pages with a similar solution would be amazing.  I've spent way too long working on this simple problem.

//table row code
<tr sprite="" id="Astilbe "><td>Astilbe 'Sprite'</td><td>12-15</td><td>Part to full shade</td><td>Shell pink flowers turning to rust cloroed seed heads</td><td></td><td>Deer resistant.  </td><td><input type="checkbox" value="16" name="id"></td></tr>

//jquery code to pass variables
<script>
$(document).ready(function() { 
        $("#tablesorted").tablesorter( );
        $("#cfContact").click(function() {
                $("#tablesorted").remove();
                $.get('plant-search-page.html' , {'variety': $('#variety').val()},  function(data) {
                    $("#searchDiv").html(data);$("#tablesorted").tablesorter( );
                });
        });
});
$('#reset').click(function() {
                location.reload();
            });
$('#printMe').live('click', function() {
        var selectedItems = new Array();
           $("input[name='id']:checked").each(function() {selectedItems.push($(this).val());});

            $.get( 'print-plants.html', {'id':selectedItems}, function(data){
                    $("#tablesorted").remove();
                    $('#searchDiv').html(data);
            });
});
</script>



//prin plants page code
<?php
$id=$_GET['id'];
$id = implode(",",$id); 
$sql = "SELECT * FROM catalog WHERE id IN ($id)";
$resultArray = $modx->db->makeArray( $sql );//put it into an array
echo "<table id='tablesorted' class='tablesorter'><thead><tr>";
echo "<th class='sortable'>Variety</th><th class='sortable'>Height (in)</th><th class='sortable'>Exposure</th><th class='sortable'>Flower Color</th><th class='sortable'>Bloom Time</th><th class='sortable'>Points of Interest </th><th class='sortable'>Print Me</th>";
echo "</tr></thead><tbody>";

foreach($resultArray as $item)//go through each record in the array
{//start looping through the data array

echo "<tr id='".$item['variety']."'>";
echo"<td>".$item['variety']."</td>";
echo"<td>".$item['height']."</td>";
echo"<td>".$item['exposure']."</td>";
echo"<td>".$item['color']."</td>";
echo"<td>".$item['bloom_time']."</td>";
echo"<td>".$item['points_of_interest']."</td>";

echo "</tr>";
}//finish looping through the data array
echo"</tbody></table>";
?>

Open in new window

0
Comment
Question by:noahlearner
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 34919526
>how to grab selcted values from check boxes with Jquery

$("#myCheckbox_ID").attr("value");
0
 

Author Comment

by:noahlearner
ID: 34919601
thanks for your response, but I think that the values are already getting grabbed.  If I use firbug and watch what happens when I click "print these"  the parameters that are getting passed are  
id[]	12 
id[]	13

Open in new window


I think the problem is on the print-plant-page.html processor page because the params that are getting sent are not being out put back to the user.
0
 
LVL 4

Expert Comment

by:janicegannon
ID: 34926602
Try changing your code

I think it's the way you are searching for your input box...

Tested here and looks good.. If that's not it, then we need to look at your PHP..
// From This
var selectedItems = new Array();
           $("input[name='id']:checked").each(function() {selectedItems.push($(this).val());});
/. To This
var selectedItems = [];
$('#tablesorted').find('input:checkbox').each(function() {
    var plantID = $(this).val();
    selectedItems.push(plantID);
});

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now