I am a beginner learning Javascript. I try to use alert boxes to alert the users, also, i try to set a hidden timer in my page. But all the codes are not working in my page especially the timer.
Please help me to solve this.
Code:
<script type="text/javascript">
var d=new Date();
var time=d.getHours();
if (time <=12){
alert("Good Morning! Please enter your name and fill in all the questions.");
}
else if(time >12 && time <18){
alert("Good Afternoon! Please enter your name and fill in all the questions.");
}
else{
alert("Good Evening! Please enter your name and fill in all the questions.");
}
var start_time, end_time, time_spent, k;
function startTimer(){
k = new Date();
start_time = k.getTime();
alert("The timer is started! Please answer the questions ASAP!!");
}
function stopTimer(){
k = new Date();
end_time = k.getTime();
time_spent = end_time - start_time;
alert("you had used " .time_spent. " to finish this form.");
document.getElementById("hidden_timer").value = time_spent;
}
function validateForm() {
var x=document.forms["quizform"]["username"].value;
if (x =="" || x ==null){
alert("Please enter your name.");
return false;
}
else{
return confirm("Are you sure to send the form?");
}
}
</script>
Bookmarks