shivani surana
shivani surana

Reputation: 57

IF ELSE statements both are getting executed on click of a link in jquery

There is a student table, if the student is pass then i want to delete the record from the table on a click on link otherwise not and for that i am checking status and showing popup. But in both the cases it is showing me both the popup.

Bellow is my anchor tag :

<a data-dialog-href="#" id="[email protected]" href="#" data-status="@Model.Status">Delete</i></a>

and Jquery :

<script>
    jQuery('body').on('click', '[data-dialog-href]', function (e) {

        var studentStatus = jQuery(this).attr('data-status'); 

        if (studentStatus  == "Completed") {
            $("#dialog-delete").dialog({
                resizable: false,
                modal: true,
                title: "Confirm Delete",
                height: 250,
                width: 400,
                buttons: {
                    "Yes": function (e) {
                        $("dialog-confirm").css("display: block");
                        $(this).dialog('close');
                    },
                    "No": function () {
                        $(this).dialog('close');
                    }
                }
            });
        }
        else
        {
            $("#dialog-ok").dialog({
                resizable: false,
                modal: true,
                title: "Inforamtion",
                height: 250,
                width: 400,
                buttons: {
                    "OK": function () {
                        $("dialog-confirm").css("display: block");
                        $(this).dialog('close');
                    }
                }
            });
        }
    });
</script>

div for popup :

<div id="dialog-delete">
    Are you sure you want to Delete Student?
</div>

<div id="dialog-ok">
    The student is not pass, Cant Delete this student.
</div>

dialog-ok is getting executed first then dialog-delete.

Please help me out. Thanks in advance.

Upvotes: 0

Views: 90

Answers (1)

induprakash
induprakash

Reputation: 269

You are getting value in studentStatus variable and you are using status variable in the rest of your code.

Upvotes: 2

Related Questions