Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  108] [ 4]  / answers: 1 / hits: 17417  / 13 Years ago, thu, november 10, 2011, 12:00:00

Is it possible onclick to create session variable with javascript or jquery then use this variable with php ?



For example someone click link at the bottom



<div id=list><a onclick =  href=javascript:void(0);>+</a></div>


there will be created variable like number=1;



then I should call it in php like :



<?php $_SESSION[number]; ?>

More From » php

 Answers
69

In order to pass a variable from JavaScript to PHP you have to make an ajax call. The easiest way is to use Jquery for that:



 <script type=text/javascript>
function submitinfo(){
$.ajax({
type: POST,
url: yourfile.php,
data: values= + $(#button1);
});

}

</script>


Also add a function to a button or something...



  <input type=button id=button1 value=<?php print $values;> onclick=submitinfo();/>


Then in yourfile.php you simply get those values from $_POST['values'] and use wherever you want.



As others have pointed out you should not be creating session parameters with JavaScript, however if you need to get something from the client side to your server side, Ajax calls is the way to do it.


[#89198] Wednesday, November 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;