-3

when I click the detail link the value of $record[id] has been sent to showUser the value store in variable e in javascript I need this value of e in php how can I get the value of e in php.

echo 
    "<td>"."
         <a  href='#?value=$record[id]' onClick='showUser($record[id])';  >Detail</a>
    "."</td>";

<script>
function showUser(str) {
var e=str;
} 
</script>
Amrinder Singh
  • 82
  • 1
  • 1
  • 10
user3000000
  • 35
  • 1
  • 1
  • 7
  • Please refer this question on stack overflow http://stackoverflow.com/questions/21072207/how-to-store-the-value-of-a-javascript-variable-into-php-variable –  Jan 01 '15 at 11:31

4 Answers4

0

Try this

echo "<td>"."<a  href='#?value=".$record[id]."' onClick='showUser(".$record[id])."';  >Detail</a> "."</td>";

That should get the variable inside the showUser onClick function.

skoumas
  • 189
  • 3
  • 12
0

Javascript variable can hold php varaible's value since js loads on client

var a = <?php echo $vari;?>

but php variable cant hold JavaScript(unless you are not sending with ajax to server) as php loads first and manipulated on server not on client

In your case you can pass $record[id]) in onClick function

"<td>"."<a  href='#?value=$record[id]' onClick='showUser(".$record[id])."';
A.B
  • 20,110
  • 3
  • 37
  • 71
0

You cannot pass javascript variable value to the php variables on the same page, as PHP code runs at the server side and it knows nothing what is going on client side.

You should pass variables to PHP code from html-form using some other way, such as Ajax. Ajax is the best way to do it. Thanks....

Amrinder Singh
  • 82
  • 1
  • 1
  • 10
0

you can pass it through an ajax call in this way:

- step 1:

$.get('name_of_php_file_you_want_to_passvalue.php?e='+e,function(data) { 

//you can do anything here with the php returned value.

})

- step 2:

And then in the php file to get that variable:

$e=$_GET['e'];
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
iniravpatel
  • 1,553
  • 16
  • 24