1

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!

1 Answer 1

1

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")

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! But it still doesn't go to saveNew function onblur.
@nom use blur instead of onblur you don't need to prefix on when using addEventListener

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.