Tuesday, 5 January 2021

MVC - jQuery - get value (text) of clicked button

 Watch this example on YouTube


 

 

1. View 


<div>
    <input type="submit" onclick="DoSomething()" value="Save" />
    <input type="submit" onclick="DoSomething()" value="Cancel" />
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            jQuery('input[type=submit]').click(function (event) {
                if (this.value == "Cancel") {
                    alert("CANCEL");
                }
                if (this.value == "Save") {
                    alert("SAVE");
                }
            });
        });
    </script>    
}

No comments:

Post a Comment