Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, no need to use the archaic <code>&lt;form&gt;</code> and posting of forms, when you are also using AJAX. So I removed all that. Makes it much simpler.</p> <p>Next, you need a way to store the value on the server, and to access it again later. One method is to use PHP Sessions (the $_SESSION variable).</p> <p>Note that I changed the name of your PHP processor file to <strong>your_php_file.php</strong>. Change it as you wish, but make sure to change it in all locations (filesystem, ajax1 and ajax2).</p> <p>Here is a working example that will do what you want.</p> <p>HTML and javascript/jQuery:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { if ($('body').width() &gt;= 960) { var sizeOfSlider = 500; } else { var sizeOfSlider = ($('body').width())/2; } $.ajax({ type: 'POST', url: 'your_php_file.php', data: 'hiddentrick=' +sizeOfSlider, dataType:'html', success: function(data) {alert(data);}, error: function(data) { //AJAX request not completed alert('error'); } }); $('#mybutt').click(function() { $.ajax({ type: 'POST', url: 'your_php_file.php', data: 'showss=yes', dataType:'html', success: function(data) { alert(data); $('#result').html(data); }, error: function(data) { //AJAX request not completed alert('error'); } }); }); }); //END $(document).ready() &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="result"&gt;&lt;?php echo $sizeofslider ?&gt;&lt;/div&gt; &lt;input type="button" id="mybutt" value="Show PHP var"/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>your_php_file.php</strong></p> <pre><code>&lt;?php session_start(); if( isset($_POST) ){ if (isset($_POST['showss'])) { echo 'Hidden value: ' . $_SESSION['sos']; }else{ $sizeofslider = $_POST['hiddentrick']; $_SESSION['sos'] = $sizeofslider; echo $sizeofslider; } }else{ echo 'No POST data'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload