Fire Hand
Fire Hand

Reputation: 26416

how to call another function in javascript?

how do i call the doSubmit() function from the conFirmUpload() when the confirm msg box is true?

<script type="text/javascript">
    function confirmUpload() {
        if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
            return true;
        }
        else
            return false;
    }

    function doSubmit(btnUpload) {
        if (typeof(Page_ClientValidate) == 'function' && Page_ClientValidate() == false) { 
            return false;
        }    
        btnUpload.disabled = 'disabled';
        btnUpload.value = 'Processing. This may take several minutes...';
        <%= ClientScript.GetPostBackEventReference(btnUpload, string.Empty) %>;    
    }
</script>

Upvotes: 0

Views: 5836

Answers (4)

Umesh Aawte
Umesh Aawte

Reputation: 4690

Change the method prototype as

function confirmUpload(obj) {
//Do some thing
}

Where obj the the button you are clicking on

Call this method as

**onclick="javaScript:confirmUpload(this)"**

Now in that if part call another method like

if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value
    +     "' ?") == true) {
    doSubmit(obj);
}

Upvotes: 0

Canavar
Canavar

Reputation: 48108

function confirmUpload() {
    if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
        var btnUpload = document.getElementById('<%= btnUpload.ClientID %>');
        doSubmit(btnUpload);
    }
}

Upvotes: 0

32423hjh32423
32423hjh32423

Reputation: 3088

Without knowing more What about this?

function confirmUpload(btnUpload) {
    if (confirm("Are you sure want to upload '" + document.getElementById("txtWS").value + "' ?") == true) {
        doSubmit(btnUpload);
    }
    else
        return false;
}

Upvotes: 1

geowa4
geowa4

Reputation: 41853

var btnUpload = document.getElementById('buttonId');
doSubmit(btnUpload);

Put that in your if-block. Make sure the button has an ID.

Upvotes: 3

Related Questions