views:

917

answers:

2

I have OnClientClick="return confirm('Make Payment?');"

tied to an asp:Button. It works fine, however, prior to popping up this confirm tho, I need to check if a textbox contains a value... How can I do this?

I need a function to return false if the textbox value is null or empty, otherwise i want to present the user with the confirm. It's not necessary if the text is null or empty. In fact if it is I would like to alert the user and return to the form to edit it. Never even showing the confirm.

Can anyone help?

Cheers, ~ck

A: 
if (document.yourtextboxID.value != '') { 
    if (confirm('Make Payment?')) {
       // Do something
    }
}
John Fisher
+4  A: 

How about this:

<script type="text/javascript">
function CheckForSubmission(txtBoxID) {
    var txtBoxEle = document.getElementById(txtBoxID);
    if (txtBoxEle == null) {
        return false;
    }
    else if (txtBoxEle.value == '') {
        alert('Please enter a value');
        txtBoxEle.focus();
        return false;
    }
    return confirm('Make Payment?');
}
</script>

OnClientClick="return CheckForSubmission(this.id);"
Matt Hamsmith