Previous | Home | Next |
How to show the Clock on Button using JavaScript
Step 1. Written below code in your application.
<html> <script language="javascript"> function get_date() { Todays = new Date(); TheDate = "" + (Todays.getMonth()+ 1) +" / "+ Todays.getDate() + " / " + Todays.getYear() document.clock.date.value = TheDate; } var timerID = null; var timerRunning = false; function stopclock (){ if(timerRunning); clearTimeout(timerID); timerRunning = false; } function startclock () { stopclock(); get_date() showtime(); } function showtime () { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds() var timeValue = "" + ((hours >12) ? hours -12 :hours) timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds timeValue += (hours >= 12) ? " P.M." : " A.M." document.clock.face.value = timeValue; timerID = setTimeout("showtime()",1000); timerRunning = true; } </script> <body onLoad="startclock()"> <form name="clock" onSubmit="0"> Date: <input type=text name="date" size=12 value=""> <br /> Time:<input type=button name="face" size=12 value="JavaScript!!"> </form> </html>
Step 2. Run the Application.
Previous | Home | Next |
Previous | Home | Next |