Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay a hidden div after a html form submit to show output
    primarykey
    data
    text
    <p>I have a html form to collect name and place and after user submit the form, the out will display at bottom of the page using php echo</p> <p>My requirement is, </p> <p>hide the <code>output div</code> before the form submit and after user enter data and submit, I have to make <code>output div</code> visible to display form output using php echo</p> <p>Here is my HTML code:</p> <pre><code>&lt;div class="main"&gt; &lt;form id="main" name="main" action="#text" method="post"&gt; &lt;div class="input"&gt; &lt;div id="name"&gt; &lt;div class="block"&gt; &lt;div class="input-quest"&gt;Your Name&lt;/div&gt; &lt;div class="input-resp"&gt;&lt;span&gt;&lt;input class="textbox" id="nm" name="nm" type="text" value="" /&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="place"&gt; &lt;div class="block"&gt; &lt;div class="input-quest"&gt;Your Place&lt;/div&gt; &lt;div class="input-resp"&gt;&lt;span&gt;&lt;input class="textbox" id="pl" name="pl" type="text" value="" /&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="submit"&gt; &lt;input id="generate" type="submit" name="script" value="generate" /&gt; &lt;input type="submit" id="clear" name="clear" value="clear" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;div class="output"&gt; &lt;?php $name = $_POST['nm']; $place = $_POST['pl']; echo "Hello, I am $name and I am from $place"; ?&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>It contain the PHP echo codes at <code>output div</code> section.</p> <p>I have searched for solution in previous questions and tried below methods mentioned there</p> <p>1.Added a inline css tag for <code>output div</code> to hide it</p> <pre><code>&lt;div id="output" style="display: none;"&gt; &lt;!-- echo php here --&gt; &lt;/div&gt; </code></pre> <p>and added javascript to call function during submit</p> <pre><code>$('main').submit(function(){ $('#output').show(); }); </code></pre> <p>It didn't work.</p> <hr> <p>2.Tried with below javascript code</p> <pre><code>$('main').submit(function(e){ $('#output').show(); e.preventDefault(); }); </code></pre> <p>It didn't work.</p> <hr> <p>3.Removed inline css for output div to hide and added the same to my css stylesheet</p> <pre><code>&lt;div id="output"&gt; </code></pre> <p>and in stylesheet</p> <pre><code>#output{ display:none; } </code></pre> <p>and used below javascript code on submit</p> <pre><code>$('main').submit(function(){ $('#output').css({ 'display' : 'block' }); }); </code></pre> <p>It didn't work.</p> <hr> <ol> <li><p>Added a onclick function along with the form submit</p> <p></p></li> </ol> <p>and submit button code:</p> <pre><code>&lt;input id="generate" type="submit" name="script" value="generate" onclick="showoutput()"/&gt; </code></pre> <p>and javascript:</p> <pre><code>showoutput(){ $('#output').slideDown("fast"); } </code></pre> <p>and with</p> <pre><code>showoutput(){ $('#output').show(); } </code></pre> <p>It didn't work.</p> <hr> <p>Please suggest a solution to do this.</p>
    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.
 

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