Skip to content
Advertisement

Code Executing on Page Load instead of OnClick

I have a code that gets executed on page load twice, despite adding the code to the ‘Click’ command.

I have placed the code ‘alert(“Testing”);’ within the portion of the code pertaining to ‘click(function(evt)‘ – grateful if someone can advise if I misunderstood the functionality of this method, as I assumed code within the subsequent brackets would only execute on button click.

Any insight would be gratefully received.

JavaScript

Advertisement

Answer

Obviously I can’t do a full test on your code, too many parts are missing to reproduce the problem and the whole environment. But I have created a skeleton of the basic structure of what I think you want to achieve. And it seems to work.

You can try the code online here: https://www.w3schools.com/php/phptryit.asp?filename=tryphp_compiler It is the only site I have found that allows you to mix html, js and php.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement