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
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

710 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