Client Side Yes/No confirmation message before inserting

I have an application that adds a form to the database (ASP.NET 2.0)

The button emits SqlDataSource_3_Inserting & SqlDataSource_3_Inserted.

I must find a way to look if the field X in the database is over the average. This method is called IsCorrectAmmounts() and returns a bool.

If bool is true, THEN the user must confirm that the ammount is OK. If it is (e.q. Yes), then the datas are inserted in the database, and the admin must be notified (STMP Email) that the user has add a value over average (method has already been made, NotifyAdmin())

With ALL that said:

How to make a confirmation box AFTER the IsCorrectAmmounts gets executed and how to make the yes response submit (e.q. Inserting) the form?

Answers


"AFTER the IsCorrectAmmounts gets executed" add the following code:

if (confirm('hey user, is this amount ok?')) {
    yourForm.submit();
}

I created a Fiddle for you that demonstrates what you want!

The HTML...

<form id='confirmationForm' action='/your/url' method='post'>
    <input id='confirmation' name="confirmation" type="hidden" value="" />
</form>​

JavaScript code...

function IsCorrectAmmounts() {
    return true;
}

if (IsCorrectAmmounts()) {
   var result = confirm('Is the amount correct')
     , form = document.getElementById('confirmationForm')
     , input = document.getElementById('confirmation');

    if (result) {
        input.value = result;
        form.submit();
    }
}​

Here is Fiddle with an AJAX version of the same code using jQuery.

function IsCorrectAmmounts() {
    return true;
}

if (IsCorrectAmmounts()) {
   var result = confirm('Is the amount correct');

   if (result) {
       $.post('/your/url', { "result": result }, function () {           
           alert('submitted');
       });
    }
}​

Need Your Help

Regular Expression to match '100702' followed by '5' or '6' followed by seven more digits

.net regex

I need a regular expression that matches a 15 character string as follows: