Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery dialog button to trigger ajax
    primarykey
    data
    text
    <p>i have a recently moved a form i was using to add some records to a database into a jquery dialog box which appears when i click a button... i was using ajax to post the data to the database by using a submit button as the trigger i have now created a button using j query in the dialog box and want to use it as the trigger for the ajax and then close the dialog box but i am unsure how to do it..</p> <pre><code> $(function() { $('form').bind('submit', function(){ $.ajax({ type: 'POST', url: "request.php", data: $("form").serialize(), success: function(data) { if(data == 1){//Success alert('Sucess'); } if(data == 0){//Failure alert('Data was NOT saved in db!'); } } }); return false; }); $("#claim").change(function(){ $("#area").find(".field").remove(); //or $('#area').remove('.field'); if( $(this).val()=="Insurance") { $("#area").append("&lt;input class='field' name='cost' type='text' placeholder='Cost' /&gt;"); } }); $( "#dialog" ).dialog({ autoOpen: false, draggable: false, modal: true, buttons: { "Add to Log": function() { $( this ).dialog( "close" ); // use this as the ajax trigger instead of the submit button bellow which was previously used }, Exit: function() { $( this ).dialog( "close" ); } } }); $( "#opener" ).click(function() { $( "#dialog" ).dialog( "open" ); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button id="opener"&gt;Open Dialog&lt;/button&gt; &lt;div id="dialog" title="Add Student"&gt; &lt;form name="form1aa" method="post" id="form1a" &gt; &lt;div id="area"&gt; &lt;input type=text name="cases" placeholder="Cases ID"&gt; &lt;select id="claim" name="claim"&gt; &lt;option value=""&gt;Select a Claim&lt;/option&gt; &lt;option value="Insurance"&gt;Insurance&lt;/option&gt; &lt;option value="Warranty"&gt;Warranty&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;select name="type" onChange=" fill_damage (document.form1aa.type.selectedIndex); "&gt; &lt;option value=""&gt;Select One&lt;/option&gt; &lt;option value="Hardware"&gt;Hardware&lt;/option&gt; &lt;option value="Software"&gt;Software&lt;/option&gt; &lt;/select&gt; &lt;select name="damage"&gt; &lt;/select&gt; &lt;br /&gt; &lt;input type=text name="comment" placeholder="Comments Box"&gt; &lt;input type="submit" value="Submit" name="Submit"&gt; &lt;!-- instead of this button triggering the ajax, use the button i created in the jquery dialog to trigger the ajax script and then close the dialog--&gt; &lt;/form&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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