Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Function on link click

Tags:

jquery

I am attempting to call up a jquery function on link click with no success:

here is my html:

<a href="..." id="removeItem" checkID="12" >Delete</a>
<a href="..." id="removeItem" checkID="13" >Delete</a>
<a href="..." id="removeItem" checkID="14" >Delete</a>

    $("#removeItem").click(function(checkID) {
    return false;
    var checkID = $(this).attr("checkID");
    $("#removeDialog").dialog( {
        buttons: {
            "No" : function () {
                $(this).dialog("destroy");
                $('input#CheckName').focus();
            },
            "Yes": function () {
                $.ajax({
                    url: "itemRemoveWS.html?id=checkID",
                    data: {
                        "action" : "remove",
                        "id" : checkID
                    },
                    success: function (data) {
                        $("#removeDialog").dialog("destroy");
                        var ang = '';
                        var obj = $.parseJSON(data);
                        $.each(obj, function() {
                           ang += '<table class="form"><tr><td width="45">' + this["CheckID"] + '</td><td width="140">' + this["Name"] + '</td><td width="95">' + this["CheckNumber"] + '</td><td align="right" width="70">$' + this["Amount"] + '</td><td width="220" style="padding-left: 15px;">' + this["Description"] +'</td><td><a href="#">Delete</a></td></tr></table>';
                        });
                        $('#container').html(ang);
                        $("input#Amount").val('');
                        $("input#CheckName").val('');
                        $("input#Check_Number").val('');
                        $("select#Company").val('MMS');
                        $("th#dept").hide();
                        $('input#CheckName').focus();
                    }
                });
            }
        }
    });
});
like image 220
Matthew Colley Avatar asked Dec 05 '12 20:12

Matthew Colley


2 Answers

You have return false; as first instruction in your click event callback function. This means you are doing nothing.

Put it at the very last line of your logic or better change it to e.preventDefault(); using

$("#removeItem").click(function(e) {...}

As a side note, $("#removeItem").click(function(checkID) {} checkID will be an ref to triggered event here, not an element id attribute.

And again, ID attribute MUST be unique for each element on each html page.

like image 119
A. Wolff Avatar answered Nov 16 '22 12:11

A. Wolff


To call of function on a link click use javascript:void(0) as your href, then add your function call to the onclick event of your link:

<a runat="server" id="myButton" href="javascript:void(0);" onclick="myFunction();" ></a>
like image 30
ORION Avatar answered Nov 16 '22 12:11

ORION