1

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("");
    });


});

2
  • 1
    Do you have an example of this working? jsFiddle or something will help identify the problem. Commented Jul 3, 2013 at 9:55
  • yours is a very good idea. it solves the problem now. next time i will try to put some code on jsFiddle Commented Jul 3, 2013 at 10:01

1 Answer 1

2

Usually happens, try using preventDefault().

 $("#btnSubmit").live('click', function (event) {
  ...
  ...
 event.preventDefault(); 
});
Sign up to request clarification or add additional context in comments.

2 Comments

better use .on('click', function (e) { .. }
@mazharkaunainbaig I'm glad I was able to help. Also consider using .on(), because live is depreciated in lasted version of jQuery. Check this for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.