I have a text box on a jsp page. I want when the page loades the value of textbox should show how much time been the page loaded. Or in simple words i want to setup a countup timer in a textbox which should start immediately and automatically when the page loads. And when the user click on submit button the user navigates to another jsp page shows that how much seconds he took to click the submit button (button was on previous page).
I am doing following HTML
<input type="text" id="timeleft" name="timeleft" />
In jquery Script i am doing the following :
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var start = new Date;
setInterval(function() {
$('timeleft').val((new Date - start) / 1000);
}, 1000); });
</script>
But the timer is not visible in textbox…? What is the error..?
Try with this (Based on your code):
For int:
$('#timeleft').val(parseInt((new Date - start) / 1000))