Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding div after ajax submit
    primarykey
    data
    text
    <p>I have this small issue, regarding an ajax form that i'm submitting (with success).</p> <p>I followed a tutorial (<a href="http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/" rel="nofollow">http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/</a>), and the form that it is submitting is just a standard contact form. However mine is sending a message through the form, and thus I want to display a message to the user, and then give the user the ability to remove the message on click.</p> <ol> <li>Form sends message.</li> <li>User receives feedback (ajax)</li> <li>How can I remove this div after it has been shown?</li> </ol> <p>HTML</p> <pre><code>&lt;div class="module send-message" id="send-message"&gt; &lt;form name="send" class="pure-form pure-form-stacked"&gt; &lt;fieldset&gt; &lt;label for="recipient" id="recipient_label"&gt;Your recipient(s):&lt;/label&gt; &lt;input type="text" name="recipient" id="recipient" class="pure-input-1 input-tags"&gt;&lt;/input&gt; &lt;label class="error" id="recipient_error" for="recipient"&gt;This field is required.&lt;/label&gt; &lt;label for="message"&gt;Your message:&lt;/label&gt; &lt;textarea name="message" maxLength="120" rows="4" class="pure-input-1" id="message"&gt;&lt;/textarea&gt; &lt;label class="error" for="message" id="message_error"&gt;This field is required.&lt;/label&gt; &lt;p id="counter" style="margin-bottom: 25px;"&gt;&lt;span&gt;0&lt;/span&gt; characters of 120&lt;/p&gt; &lt;input type="submit" name="submit" id="submit_btn" class="button btn-large btn-warning" value="Pipit"&gt;&lt;/input&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>JS/Jquery:</p> <pre><code>var dataString = 'recipient='+ recipient + '&amp;message=' + message + '&amp;terms=' + terms; //alert (dataString);return false; $.ajax({ type: "POST", url: "process.php", data: dataString, success: function() { $('#send-message').html("&lt;div id='feedback'&gt;&lt;/div&gt;"); $('#feedback').html("&lt;h2&gt;Your message has been sent!&lt;/h2&gt;") .append("&lt;p&gt;Click anywhere to hide this message.&lt;/p&gt;") .hide() .fadeIn(); } }); return false; }); }); </code></pre> <p>:: UPDATE :: Thanks to a number of people on this fantastic site, I got it to work!</p> <p>However, there are two minor flaws: </p> <ol> <li>I want the form to be refreshed (all data removed from it).</li> <li>When the feedback message is shown for the first time, it goes away like it should. However when i re-submit the form, the feedback form will linger to the bottom.</li> </ol> <p>Can any1 help here? </p> <p>Thank you so much!</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.
    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