How can I get the value of an input with JavaScript?

-2

This is my input and I need to obtain the value by JavaScript of preference that is pure and not with frameworks or if there is no other way or mode.

<input 
  type="text" class="whsOnd zHQkBf" 
  jsname="YPqjbf" autocomplete="off" 
  tabindex="0" aria-label="Nombre" 
  value="FJ" dir="ltr" data-initial-value="FJ" 
  autofocus="" id="searchInput">
    
asked by Mr. Boot 13.09.2018 в 23:56
source

2 answers

2

Try this:

var value = document.getElementById('searchInput').value;

Or with JQuery :

var bla = $('#searchInput').val();

Greetings.

    
answered by 13.09.2018 / 23:57
source
0

I made a small code with your input I hope it works for you:

var boton = document.getElementById("boton");

boton.addEventListener("click", () => {

  var input = document.getElementById("searchInput");
  var valor = input.value;

  alert("El valor del campo es:"+ valor);
  
});
<input type="text" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="Nombre" value="FJ" dir="ltr" data-initial-value="FJ" autofocus="" id="searchInput">

<button id="boton">Obtner valor</button>
    
answered by 14.09.2018 в 00:23