Reputation: 39
I'm using a input Text date type and i'm trying to get value when input text is fill or some value clicked inside, what event i need to catch value inside the input?
I put a keyup from jquery but only work it when someone press a key, but in this field date type you can click it in the arrows and my values do not update and this value neither update when i get value from database.
<script type="text/javascript">
$(document).ready(function(){
$("input#name").on("keyup",function(){
var valor= $(this).val();
var date=age(value)
$("div#messaje p").html(date);
}) ;
});
</script>
<body>
Enter your name: <input id="name" type="date">
<div id="messaje"><p>value update from input text date type</p></div>
</body>
I hope to get the value of my input no matter how the data reaches him
Upvotes: 0
Views: 506
Reputation: 3721
Change the event keyup
to change
$(document).ready(function() {
$("#dateInput").on("keyup change", function() {
var valueDate = $(this).val();
console.log(valueDate);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I'm using a input Text date type and i'm trying to get value when input text is fill or some value clicked inside, what event i need to catch value inside the input? I put a keyup from jquery but only work it when someone press a key, but in this field
date type you can click it in the arrows and my values do not update and this value neither update when i get value from database.
<body>
Enter your name: <input id="dateInput" type="date">
<div id="messaje">
<p>value update from input text date type</p>
</div>
</body>
Upvotes: 0
Reputation: 58
well I think your first problem is that you using the wrong event you should use change this is your input
<input type="date" id="start">
then you should write your event handler like this
object = document.getElementById("start");
object.addEventListener("change", function(){
alert (document.getElementById("start").value)
});
Upvotes: 0
Reputation: 4182
A key-up event wont be triggered on the datePicker because you don't use a keyboard to interact with it. Listen for the change event instead.
Always keep your javascript above where your body tag ends.
I don't know what you tried to do in var date=age(value)
, for time being I've omitted it.
Attached working snippet.
Thanks, A.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
Enter your name: <input id="name" type="date">
<div id="messaje"><p>value update from input text date type</p></div>
<script type="text/javascript">
$(document).ready(function(){
$("#name").on("change",function(){
var valor = $(this).val();
$("#messaje p").html(valor);
});
});
</script>
</body>
Upvotes: 1