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

superblowncolon
  • 183
  • 1
  • 1
  • 15
  • Check these out: http://stackoverflow.com/questions/25395395/how-to-run-a-php-script-from-javascript | http://stackoverflow.com/questions/16834138/javascript-function-post-and-call-php-script | http://stackoverflow.com/questions/5306479/calling-php-scripts-from-javascript-without-leaving-current-page – mariocatch May 07 '17 at 23:09
  • There's no php or mysql code here, which IMHO automatically makes this question both unclear and too broad. There's also no HTML to support the code posted. – Funk Forty Niner May 07 '17 at 23:47
  • Your acceptance record is questionable, regarding past questions with possible solutions given. – Funk Forty Niner May 07 '17 at 23:49
  • I will go back and accept the answers that solved my issues. I apologize for neglecting to do that. – superblowncolon May 08 '17 at 00:57

3 Answers3

0

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

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'];

Ümit Aparı
  • 540
  • 2
  • 6
  • 23
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
});
Nathan
  • 491
  • 4
  • 8