Magento 2 how to add a Javascript addeventlistener to elementIf 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

Was Spock the First Vulcan in Starfleet?

Go Pregnant or Go Home

Star/Wye electrical connection math symbol

Trouble understanding overseas colleagues

How does a character multiclassing into warlock get a focus?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

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

Implement the Thanos sorting algorithm

What's a natural way to say that someone works somewhere (for a job)?

How to prove that the query oracle is unitary?

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

Why "be dealt cards" rather than "be dealing cards"?

What defines a dissertation?

How could Frankenstein get the parts for his _second_ creature?

Displaying the order of the columns of a table

How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?

How does it work when somebody invests in my business?

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

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

Mapping a list into a phase plot

The plural of 'stomach"

What's the purpose of "true" in bash "if sudo true; then"



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

          Jet Time Laivasto | Lähteet | Aiheesta muualla | NavigointivalikkoJet Time - The CompanyThe CompanyManagementJet Time aloittaa lauantaina Suomi-rekisterissä olevalla Boeing 737 -koneellaJettime Finland Fleet Details and HistoryJettime Fleet Details and HistoryRegional Jet OÜ takes over ATR production for SASJet Time Returns To Its Core BusinessYhtiön kotisivutlaajentamalla

          Olympian arkeologinen museo Sisällysluettelo Historia ja rakennus | Kokoelmat | Lähteet | Aiheesta muualla | Navigointivalikko37°38′36″N, 21°37′46″EInfobox OKArchaeological Museum of Olympia: HistoryArchaeological Museum of Olympia: DescriptionΜουσείο Ιστορίας των Ολυμπιακών Αγώνων της Αρχαιότητας: ΙστορικόArchaeological Museum of Olympia

          Äpy Sisällysluettelo Äpyt kautta historian | Esimerkkejä Äpy-huumorista | Katso myös | Kirjallisuutta | Aiheesta muualla | Navigointivalikkowww.äpy.fi