Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a few things you need to change. Firstly this:</p> <pre><code>&lt;form name="rpt" class="rpt" id="rpt" action="" onclick="doSave(); return false;"&gt; </code></pre> <p>isn't the jQuery way. Plus its not the click() event you want. Do this:</p> <pre><code>&lt;form name="rpt" class="rpt" id="rpt" action=""&gt; &lt;script type="text/javascript"&gt; $(function() { $("#rpt").submit(do_save); }); &lt;/script&gt; </code></pre> <p>The construction:</p> <pre><code>$(function() { .. }); </code></pre> <p>means "when the document is ready, execute this code". It is shorthand for and exactly equivalent to the slightly longer:</p> <pre><code>$(document).ready(function() { .. }); </code></pre> <p>This code:</p> <pre><code>$("#rpt").submit(doSave); </code></pre> <p>means "find the element with id 'rpt' and attach an event handler to it such that when the 'submit' event is executed on it, call the do_save() function".</p> <p>And change doSave() to:</p> <pre><code>function doSave() { $('.error').hide(); $(".rpt").click(function() { $('.error').hide(); var textArea = $('#report'); if (textArea.val() == "") { textArea.show(); textArea.focus(); return false; } else { return true; } var dataString = '&amp;report='+ report; alert (dataString);return false; $.ajax({ type: "POST", url: "body.php?action=customer", data: dataString, dataType: 'json', success: function(data){ $('#cust input[type=text]').val(''); var div = $('&lt;div&gt;').attr('id', 'message').html(data.message); if (data.success == 0) { $('#cust input[type=text]').val(''); $(div).addClass('ajax-error'); } else { $('#cust input[type=text]').val(''); $(div).addClass('ajax-success'); } $('body').append(div); } }); }); return false; } </code></pre> <p><strong>Note:</strong> return false is in the correct place now so it actually prevents the form submitting back to the server. action="" just means the form will submit back to its current location so you have to prevent that.</p>
 

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