Francis Vargas Francis Vargas - 2 months ago 10
Javascript Question

How to add an alert statement to JQuery?

I just want to show an alert when the computation is done. It is inside my JQuery script.

Here's my code:

<script language="javascript">
$('document').ready(function() {
$('#payable').change(function() {
var str = $('#payable').val();
var value = $('#value').val();
if (str == "1 Week") {
var result = value / 6;
$("#deduc").val(result);
} else if(str == '1 Month'){
var result = value / 24;
$("#deduc").val(result);
} else if(str == '2 Months'){
var result = value / 48;
$("#deduc").val(result);
}
})
})
</script>

Answer

If I'm not mistaken to add an alert after the function is done you can just add one line before the end of your script

$('#payable').change(function() {
    var str = $('#payable').val();
    var value = $('#value').val();
    if (str == "1 Week") {
       var result = value / 6;
       $("#deduc").val(result);
    } else if(str == '1 Month'){
       var result = value / 24;
       $("#deduc").val(result);
    } else if(str == '2 Months'){
       var result = value / 48;
       $("#deduc").val(result);
    }
    alert("Completed!");
})