maztt
maztt

Reputation: 12304

jquery click event is called multiple times

i have a jquery dialog with a add item button and a textbox adding whatever in the textbox to the table in the dialog.

it add the items fine the first time . but when i close it and then open it. it started calling the button click event multiple times. what could be wrong? this is a click event executed on the dialog.

<script language="javascript" type="text/javascript">

$(document).ready(function () {


    $("#btnSubmit").live('click', function () {
        $("#namingarray").attr("value", "-1");
        $('.clstr1').each(function () {
            var notextbox = $("#namingarray").attr("value");
            var vc = parseInt(notextbox) + 1;
            $("#namingarray").attr("value", vc);
        });

        var metatext = $.trim($("#metatxt").val());
        var namingarray = $("#namingarray").attr("value");
        var vc1 = parseInt(namingarray) + 1;
        $("#namingarray").attr("value", vc1);

        $("#Dropdownadditems").append("<tr class=\"clstr1\" id=\"row-" + vc1 + "\"  ><td>" + metatext + "</td><td><a class='linkbuttons' href='#' id=" + vc1 + ">Delete</a></td></tr>");
        $("#metaItems").append("<input type=\"hidden\" value=\"" + metatext + "\" name=\"Dropdownadd\"  id=\"MetaValue-" + vc1 + "\" />");
        $("#metatxt").val("");
    });


});

Upvotes: 1

Views: 692

Answers (1)

Praveen
Praveen

Reputation: 56539

Usually happens, try using preventDefault().

 $("#btnSubmit").live('click', function (event) {
  ...
  ...
 event.preventDefault(); 
});

Upvotes: 2

Related Questions