Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Dialog box Button function running on page load
    primarykey
    data
    text
    <p>I want to raise a jQuery Dialog box which has 2 buttons. So that the user can decide to continue with the overwrite operation or not. </p> <p>One button, the "no" button should do nothing except close the dialog window. The "Yes" button should call a function that make a jQuery post call to an action method on my controller. </p> <p>The problem is that my action method appears to be run on page load, its not waiting for the dialog box to even show. </p> <p>Here is the markup for the dialog</p> <pre><code> &lt;div id="dialog" title="My Dialog Box"&gt; &lt;p&gt; Ballance Already Exsists. Do you wish to overwrite?&lt;/p&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#dialog").dialog({ bgiframe: true, autoOpen: false, modal: true, buttons: { 'OK': overWriteBalance(), 'NO': $(this).dialog('close') } }); }); &lt;/script&gt; </code></pre> <p>and here are the functions </p> <pre><code> balanceCheckPost = function (data) { $("#existCheck").val(data); if (data) { // Does Exist $("#existCheck").val("Exist"); // raise confirmation popup $('#dialog').dialog("open"); } else { // Does Not Exist $("#existCheck").val("NOT Exist"); // insert Item var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/insert", balance, confirmChange ); } }; function overWriteBalance() { // insert Item var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/edit", balance, confirmChange ); }; </code></pre> <p>and here is the code in my controller. </p> <pre><code> public void edit(Balance bal) { var dataContext = new DataDataContext(); var balToEdit = dataContext.Balances.Single(b =&gt; b.Date == bal.Date); balToEdit.Amount = bal.Amount; dataContext.SubmitChanges(); } </code></pre> <p>The problem is that the edit function in my controller is runing on page load. </p> <p>Is it because I have the definition of my dialog buttons in $(document).ready, so its running the method or something.</p> <p>Thanks</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