Answers for "getting input value into button on click javascript"

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 "getting input value into button on click javascript"

Browse Popular Code Answers by Language