Search code examples
asp.netjavascript

Message / confirm dialog


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


Solution

  • 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) {
            return Boolean(confirm("Are you sure?"));
        }
    }
    

    This function can now be added to the buttons onclick method

    <input type="Button" value="Submit" onclick="return FormSubmit()" />