How to apply a custom function on html code after inserted from javascript

Hello, I need help in javascript.

I have a button in index.html file somewhere on click this button a popup window appears on-screen which includes Signup Form.

this popup window code comes from a javascript’s function using insertAdjacentHTML function

Here is a problem…

This form includes a submit button.

in javascript i use an addEventListener and apply a form validation function on click submit button but when page load it gives error

“Cannot read property ‘addEventListener’ of null”

popup window working fine but submit button also don’t work

i shell be very thankful if you help me find a very good solution.

1 Like

Without seeing your code that could be difficult.

1 Like

A likely cause is that the HTML code doesn’t yet exist when the JavaScript code is running.

The usual technique is to place scripting at the end of the body, that helps to alleviate such issues.
But, your situation is one where the code doesn’t even seem to exist until after the popup has done its thing.

Details of how that popup does its thing is required. A link to an appropriate page that lets us experience the problem is most suited here.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.