Magento 2 how to add a Javascript addeventlistener to elementIf Maximum order value is above £X show...

Valid Badminton Score?

Can somebody explain Brexit in a few child-proof sentences?

Modify casing of marked letters

What would be the benefits of having both a state and local currencies?

Was Spock the First Vulcan in Starfleet?

What are the ramifications of creating a homebrew world without an Astral Plane?

Why Were Madagascar and New Zealand Discovered So Late?

Is there an Impartial Brexit Deal comparison site?

Is there a good way to store credentials outside of a password manager?

Increase performance creating Mandelbrot set in python

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past

Everything Bob says is false. How does he get people to trust him?

How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?

Is the destination of a commercial flight important for the pilot?

Is it correct to write "is not focus on"?

Print name if parameter passed to function

Star/Wye electrical connection math symbol

What is the intuitive meaning of having a linear relationship between the logs of two variables?

Why does John Bercow say “unlock” after reading out the results of a vote?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

Best way to store options for panels

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

There is only s̶i̶x̶t̶y one place he can be



Magento 2 how to add a Javascript addeventlistener to element


If Maximum order value is above £X show Javascript AlertInjecting javascript in specific pageMagento 2: Adding external CSS and JS to only one content page, and use jquery functions inside the contentMagento 2: Add UI Multiselect DropdownHow do you populate a Magento_UI dynamicRows element?when proceed to checkout take very long and getting proxy errorLoading Javascript for minicart in Magento 2add custom js to the certain input element on the checkout pageMagento Checkout Stuck: Failed to load the “Magento_Checkout/js/view/payment” componentSOLVED - Add js to home page













0















I am trying to add an event listener to an element, but no matter what I try, it won't work. Here is what I have so far (this is in the html web templates page):



window.addEventListener('load',function(){
document.getElementById('authnetcim-submit').addEventListener("click", function(){
alert('Alert Message');
});
});


Everyone keeps saying that the listener needs to be wrapped in window.addEventListener('load'), as you need to wait for the page to load before you can add the listeners, but that still won't work for me either. There are no errors and nothing logs to the console. The Id is correct and it's the only id of that name used on the page.



Any help is appreciated.









share



























    0















    I am trying to add an event listener to an element, but no matter what I try, it won't work. Here is what I have so far (this is in the html web templates page):



    window.addEventListener('load',function(){
    document.getElementById('authnetcim-submit').addEventListener("click", function(){
    alert('Alert Message');
    });
    });


    Everyone keeps saying that the listener needs to be wrapped in window.addEventListener('load'), as you need to wait for the page to load before you can add the listeners, but that still won't work for me either. There are no errors and nothing logs to the console. The Id is correct and it's the only id of that name used on the page.



    Any help is appreciated.









    share

























      0












      0








      0








      I am trying to add an event listener to an element, but no matter what I try, it won't work. Here is what I have so far (this is in the html web templates page):



      window.addEventListener('load',function(){
      document.getElementById('authnetcim-submit').addEventListener("click", function(){
      alert('Alert Message');
      });
      });


      Everyone keeps saying that the listener needs to be wrapped in window.addEventListener('load'), as you need to wait for the page to load before you can add the listeners, but that still won't work for me either. There are no errors and nothing logs to the console. The Id is correct and it's the only id of that name used on the page.



      Any help is appreciated.









      share














      I am trying to add an event listener to an element, but no matter what I try, it won't work. Here is what I have so far (this is in the html web templates page):



      window.addEventListener('load',function(){
      document.getElementById('authnetcim-submit').addEventListener("click", function(){
      alert('Alert Message');
      });
      });


      Everyone keeps saying that the listener needs to be wrapped in window.addEventListener('load'), as you need to wait for the page to load before you can add the listeners, but that still won't work for me either. There are no errors and nothing logs to the console. The Id is correct and it's the only id of that name used on the page.



      Any help is appreciated.







      magento2 magento2.2 javascript





      share












      share










      share



      share










      asked 3 mins ago









      Eric BrownEric Brown

      1456




      1456






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267529%2fmagento-2-how-to-add-a-javascript-addeventlistener-to-element%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267529%2fmagento-2-how-to-add-a-javascript-addeventlistener-to-element%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          迭戈·戈丁...

          A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

          1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...