0
I’m trying to create a function that takes the value of an input field and puts it in div. But I’m not getting it to work.
Note: I need to take only the numerical values.
Just follow my code:
$( "#testar" ).click(function() {
$('#txtDistancia').on('input', function () {
var valor = $(this).val();
$('#valorkm').html(valor);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="distancia" type="text" id="txtDistancia" value="7,5 km">
<p></p>
<input type="button" value="Testar" id="testar" class="btn btn-success" />
<p></p>
<div id="valorkm"></div>
UPDATE: I would like the person to test the localhost code, because two people helped me, I saw the code working here and also through Fiddle, but when testing on localhost does not work.
Is there an error in the browser console? this javascript is set in html after the right jquery include?
– Rui Ferreira