Skip to content
Advertisement

How do I wait for input to be filled in an html page and then print it’s value to the console in javascript?

I have a HTML page with an input field
Someone enters some text into it
They click a button

I want to grab the value of the input field AFTER they click the button with some JS code(client-side) and then print it to the console/save it to a file.

How would I go about doing this? I’ve tried looking but I can’t find anything like this at all :/

Thanks! 🙂

Advertisement

Answer

This example should help you to achieve your goals.

const inputNode = document.getElementById('input');
const buttonNode = document.getElementById('button');

buttonNode.addEventListener('click', () => {
  const inputValue = inputNode.value;
  
  // do what ever you wan't
});
<input id="input" type="text" />
<button id="button">Click</button>
Advertisement