Note that there are some explanatory texts on larger screens.

plurals
  1. POStop html form submission
    primarykey
    data
    text
    <p>Hi I have HTML form which I have an onclick event where it prompts the user e.g. if sure yes/no. If no is selected its suppose to stop the form from submitting but it seems to process through as the dialog is being called async. I'm using a jquery plugin <a href="http://marcosesperon.es/apps/messi/" rel="nofollow">http://marcosesperon.es/apps/messi/</a> for displaying my prompt.</p> <p>Below is a snippet of my code:</p> <pre><code> &lt;div id="buttonCommnads"&gt; &lt;button type="submit" class="k-button cancel" id="save" value="Save" title="Save inspection so it may be submitted at a later time" onclick="processCommand(COMMAND.SAVE);"&gt;Save&lt;/button&gt; &lt;button type="submit" class="k-button" id="Submit" value="Submit" title="Submit inspection" onclick="return processCommand(COMMAND.SUBMIT);"&gt;Submit&lt;/button&gt; @*&lt;button type="submit" class="k-button" id="email" title="Generate draft email for inspection photos" onclick="processCommand(COMMAND.EMAIL);"&gt;Email&lt;/button&gt;*@ &lt;button type="button" class="k-button" id="cancel" title="Discard changes" onclick="location.href='@Url.Action("Index", "Inspections")'"&gt;Cancel&lt;/button&gt; &lt;/div&gt; </code></pre> <p>and then the javascript function:</p> <pre><code>&lt;script&gt; var COMMAND = { SAVE: { value: 0, name: "Save", tense: "saved" }, EMAIL: { value: 1, name: "Email", tense: "emailed" }, SUBMIT: { value: 2, name: "Submit", tense: "submitted" }, }; function processCommand(command) { if (command == COMMAND.EMAIL) { } else if (command == COMMAND.SAVE) { $('#Submit').val(command.name); $('#inspectionForm').submit(); } else if (command == COMMAND.SUBMIT) { $('#Submit').val(command.name); var photosAttached = '@Model.Survey.SitePhotoes.Count()'; console.log('processCommand: submit - begin'); if (photosAttached &gt;= 1) { console.log('processCommand: submit photos attached.'); return true; } else { console.log('processCommand: prompt messi.'); new Messi('Are you sure you wish to submit as no inspections photos are currently attached?', { title: command.name + ' Inspection', buttons: [{ id: 0, label: 'Yes', val: 'Y', btnClass: 'btn-success' }, { id: 1, label: 'No', val: 'N', btnClass: 'btn-danger' }], modal: true, callback: function (val) { if (val == 'Y') { console.log('processCommand: yes.'); return true; } else { console.log('processCommand: no.'); return false; } } }); } console.log('processCommand: submit - end'); } </code></pre> <p>} </p> <p>I'm using ASP.NET MVC 4 and I'm fairly new to web development so please excuse my ignorance. Any help greatly appreciated.</p> <p>Vince.</p>
    singulars
    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