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
251 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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

18 Experts available now in Live!

Get 1:1 Help Now