-1

so I got this really simple jQuery datatable, and i'm trying to get my selected value into a php variable. Here is my code:

<script>
        var hlr = 0;   // Reference to the currently highlighted row

function rowClick()
{
   if (hlr)
      $("td:first", hlr).parent().children().each(function(){$(this).removeClass('markrow');});
   hlr = this;
   $("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});

   // You can pull the values out of the row here if required
   var a = $("td:first", this).text();
   var b = $("td:eq(1)", this).text();

    //$_SESSION['Klantnaam']="+a+");

   alert("Keuze = "+a+""); //this is what I need in my PHP session variable.
}
      </script>

Thanks for reading, a response is highle appreciated.

Drupz
  • 17
  • 3
  • 1
    So what is the problem? – user2936213 Feb 03 '14 at 09:30
  • 1
    I have no idea how often this question was already asked ... http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php – Realitätsverlust Feb 03 '14 at 09:32
  • PHP session variables are set on the server. You are working with a client side script. You'll need to send the contents of the client side "a" variable to the server somehow. You could do that with an asynchronous javascript request. – HaukurHaf Feb 03 '14 at 09:33
  • Could anyone give me a code sample on how to do this? – Drupz Feb 03 '14 at 09:56

1 Answers1

0

I had already faced this question on my recent project

Here is my solution to you

But i had to take value in to session variable so

STEPS:

  1. Created a php file which puts value to session variable

  2. Send a ajax request to that php file with js var value

Krunal Panchal
  • 778
  • 7
  • 14