Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So it seems you want the page to work in either js enable or not.</p> <p><a href="http://pastie.org/1269741" rel="nofollow">Try this</a>.</p> <p>If I was you, I would rethink my design I would break the code up into separate files. This is really a spaghetti design.</p> <pre><code>&lt;?php if (array_key_exists('js', $_POST)) { $js = $_POST['js']; if (array_key_exists('num', $_POST)) { $num = $_POST['num']; echo "&lt;div&gt;$num&lt;/div&gt;"; exit(); } } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"&gt;&lt;/script&gt; &lt;!-- &lt;script type="text/javascript" src="./jquery.form.js"&gt;&lt;/script&gt;--&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("#testform").submit(function() { var serialized = $(this).serialize() + '&amp;js=1'; $.post("1.php", serialized, function(data) { $('.result').append(data); }); $('#number_input').val(''); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="result"&gt; &lt;?php session_start(); if (array_key_exists('num', $_POST)) { $numbers = array(); if(array_key_exists('numbers', $_SESSION)) { $numbers = $_SESSION['numbers']; } $numbers[] = $_POST['num']; foreach($numbers as $num) { echo "&lt;div&gt;$num&lt;/div&gt;"; } $_SESSION['numbers'] = $numbers; } else { $_SESSION['numbers'] = array(); } ?&gt; &lt;/div&gt; &lt;div&gt; &lt;form id="testform" action="1.php" method="post"&gt; &lt;label for="number_input"&gt;Number: &lt;/label&gt;&lt;input id="number_input" type="text" name="num"/&gt; &lt;input type="submit" value="Submit Comment"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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