0
How do I show value I typed in input
after clicking the button?
mine always returns empty:
var x = document.getElementById("usuario").value;
var usuario = $("#usuario").value; //document.getElementById("user").value; // $("#user").value;
var senha = $("#pwd").value;
function Enviar() {
$("#enviar").on('click', function() {
alert(usuario)
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="search">
<input id="term" type="text" value="" />
<button id="hit" type="button" name="">Search</button>
</div>
<form>
<fieldset>
<div class="controls">
<label for="id">User ID:</label>
<input type="text" id="usuario" name="usuario" />
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd" />
<input type="submit" id="enviar" onclick="Enviar()" value="Submit" />
</div>
</fieldset>
</form>
Utilize
$("#usuario").val()
and remove thetype
button Submit.– Valdeir Psr
There’s no point in taking Ubmit if you’re not going to lose buttom property
– Cezar Mdlosci
There is a type="button" in this case would not be better?
– Maycon F. Castro
I didn’t pay attention and I thought it was a
button
. Anyway, use it anywaypreventDefault
or use abutton
(semantically is better).– Valdeir Psr