Answers for "javascript get input value on button click"

1

javascript get value of input on button click

<form action="/">
  <label for="">Whatever you want</label>
  <input type="text" id='form'>
  <input type="submit" id="submit">
</form>

<script>
  const btn = document.getElementById('form');
  
  btn.addEventListener('click', (e) => {
  	e.preventDefault(); // disable the refresh on the page when submit
    const value = document.getElementById('submit').value;
    
    console.log(value);
  });
</script>
Posted by: Guest on January-25-2021

Code answers related to "javascript get input value on button click"

Browse Popular Code Answers by Language