Nom
Nom

Reputation: 103

javaScript create checkBox dynamically and add event

I created check Box in javaScript:

var checkbox = document.createElement('input');
                    checkbox.type = "checkbox";
                    checkbox.name = "abc";
                    checkbox.addEventListener("onblur", saveNew("abc"));
                    checkbox.id = 1;

My problem is that he goes to saveNew function when he create the checkbox. And I want that he will go only onblure. How can I do it? thanks!

Upvotes: 1

Views: 63

Answers (1)

Satpal
Satpal

Reputation: 133403

You need to provide the event handler function which will be invoked when the event occurs.

checkbox.addEventListener("blur", function(){
   saveNew("abc");
});

Currently you are setting the return value of the function saveNew("abc")

Upvotes: 1

Related Questions