Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
304 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 83

Accepted Solution

by:
leakim971 earned 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 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