-1

I have this function that fires when a checkbox form is submitted:

function report_build() {
   var checked_count = 0;
   var where = ""
   $('.peer:checked').each(function (i) {
   checked_count++;
   var label = $(this).parent().next().html();
   where +=  "'" + label + "', "   
                });
   $('#tabs-1').html(where);
   $('#ui-id-6').click();

            }

I want to send the where variable to a PHP script to use in the where clause of a select list. What's the easiest way to do that?

Thanks!

4

3 Answers 3

0

You will have to use AJAX for that.

A simple post should do the job:

$.post('handle-sql.php', {where: where}, function(data) {
    // In the handle-sql.php script, use $_POST['where'];
    // Callback function: called after php script is completed
    // Where 'data' is the echo'ed data from the PHP script
});
Sign up to request clarification or add additional context in comments.

Comments

0

You should try to POST or GET it with an HTML <form>. They send to PHP, but otherwise javascript is run client-side.

Comments

0

I'm not quite sure about what you're asking but if I'm not mistaken you want to send a variable from javascript to php. You can easily do that with ajax. Here's an example;

$.ajax(
{
    type: "POST",
    url: "your_php_name.php",
    data: { 
        'where' : where
    },
    dataType: "html",
    success: function(answer)
    {
        //fires when php finishes it job.           
    }
});

And on php side, you can read the variable with $_POST['where'];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.