Have Time Automatically Be In The Input Type="time"
I am trying to display the current time as the value in my input upon loading the page. However, its not working for some reason. Any suggestions? Thanks for any help.
Solution 1:
Use
var now = newDate();
Instead of
var current = newDate();
Solution 2:
Use valueAsDate to make the input display the value
<body><inputtype="time"id="theTime"><script>
$(document).ready( function() {
var now = newDate();
//now2 prevents the milliseconds from showing up in the inputvar now2 = newDate(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
$('#theTime')[0].valueAsDate = now2;
});
</script></body>
Solution 3:
You are using wrong variable use current
instead,
$(document).ready( function() {
var current = newDate();
var minute = (current.getMinutes() + 1);
var seconds = current.getSeconds();
if(minute < 10)
minute = "0" + minute;
if(seconds < 10)
seconds = "0" + seconds;
var today = current.getFullYear() + '-' + minute + '-' + seconds;
$('#theTime').val(today);
});
See the working code here
Solution 4:
<!DOCTYPE html><html><head><metacharset="UTF-8"><scriptsrc="Scripts/Global.js"></script><scriptsrc="Scripts/jquery.js"></script><linkrel="stylesheet"type="text/css"href="Styles/Design.css"></head><body><inputtype="time"id="theTime"><script>
$(document).ready(function() {
let now = newDate();
$('#theTime').val(now.getHours()+":"+ now.getMinutes());
});
</script></body></html>
Post a Comment for "Have Time Automatically Be In The Input Type="time""