views:

194

answers:

3

I have a need for a confirm message box from a button click, but only on some conditions. I am cheking two values on the aspx.page, and if one is higher than another, I need a confirmation from the user. Are there any ( simple) way of doing this ? I have been reading about javascript and alert messages, but I cant seem to figure out this one.... I am using RadStudio 2007, .net application.

Any help are appriciated. Anja

+4  A: 

JavaScript provides what you need with the confirm function. This displays a confirmation box allowing the user to 'OK' or 'Cancel'. An example function based on what you require:

function FormSubmit(){
    var value1 = document.getElementById("Textbox1").value;
    var value2 = document.getElementById("Textbox2").value;
    if(value1 > value2){
        if(confirm("Are you sure?")) {return true;} else {return false;}
    }
}

This function can now be added to the buttons onclick method

<input type="Button" value="Submit" onclick="return FormSubmit()" />
Andy Rose
+2  A: 

This is a confirm message example in javascript :

<a href="deleteUser.aspx?id=231" onclick="return confirm('Are you sure you want to delete user ?')">Delete User</a>

Some Other Helpful Examples

Canavar
A: 

Thank you Andy, works like a charm :)