How to accept value from input (html) using js?

  • 0
    https://codepen.io/eldgammel/pen/vYKyVMW?editors=1010 - here is my code
    the essence is simple, everything is filled in, and the values ​​should go to the console (of the one that was filled)
    but, alas, it does not work, it gives the error "Uncaught Typeerror: Cannot set property 'onsubmit' of undefined"
    P.S. need in pure js (no jQuery and all that)
    Help pliz
    JavaScript Jacob Avila, May 17, 2020

  • 1 Answers
  • 0
    You can do it this way (I just replaced onsubmit with click for convenience)



    const form = document.forms.cargoData;


    form.addEventListener('click', function(e) {
    e.preventDefault();
    const chooseService = form.chooseService.value;
    console.log(chooseService)
    });




    And change the action of the form to name
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!