I am using jQuery to convert minutes into hour, whenever minutes exceeds more than 59; hour is changed to 1.
I have tried this so far-
<script type="text/javascript">
$(document).ready(function () {
$('.minutes').change(function () {
if ($('.minutes').val() > 59) {
Math.floor($('.hour').val()) = ($(this).val()) + 1;
}
});
});
</script>
Jsfiddle link- Minutes into hour
I want minutes to show converted hour every time it exceeds multiplications of 60.
Thank you for your time.
here's the JSFiddle
$(document).ready(function () {
$('.minutes').change(function () {
if ($('.minutes').val() > 59) {
//Math.floor($('.hour').val() )= $(this).val() + 1;
var min = $('.minutes').val();
var hr = Math.floor(min / 60);
var hrTemp = Math.floor($('.hour').val());
var remMin = min % 60;
$('.hour').val(hr + hrTemp);
$('.minutes').val(remMin);
}
});
});
In cased that minutes is more than 120, adding 1 doesn't produce the correct hour, instead of hard-coding the value by adding 1, you can divide the minutes by 60 and add the result to the .hour element's value.
$(document).ready(function () {
$('.minutes').change(function () {
var min = + this.value;
if (min > 59) {
this.value = min % 60;
$('.hour').val(function (_, oldValue) {
return +oldValue + Math.floor(min / 60);
})
}
});
});
http://jsfiddle.net/GZEaH/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With