I'm Trying To Create Custom Date Object.
but am comeing back with a NaN error.
Source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Alarm</title>
</head>
<style type="text/css">
</style>
<script type="text/javascript">
function startup() {
curdate = new Date();
h = curdate.getHours();
m = curdate.getMinutes();
s = curdate.getSeconds();
time = h + ":" + m + ":" + s;
AS_h = document.getElementById('input_hr').value;
AS_m = document.getElementById('input_mn').value;
AS_s = document.getElementById('input_sc').value;
AV_h = parseInt(AS_h);
AV_m = parseInt(AS_m);
AV_s = parseInt(AS_s);
alarmtime = AV_h + ":" + AV_m + ":" + AV_s;
document.getElementById('curtime').innerHTML=time;
setTimeout("startup()",1000);
document.getElementById('alarmtime_').innerHTML=alarmtime;
}
</script>
<body onLoad="startup()">
<span style="font-size:40px;">
Current Time:
</span>
<br />
<span style="font-size:40px;" id="curtime"></span>
<br />
<span id="alarmtime_"></span>
<hr />
<input type="text" class="" id="input_hr">
<input type="text" class="" id="input_mn">
<input type="text" class="" id="input_sc">
<br />
<input type="button" value="+1hr" onClick="">
<input type="button" value="+10min" onClick="">
<input type="button" value="+60sec" onClick="">
<input type="button" value="Start Alarm" onClick"alarmset()">
</body>
</html>
Date object problems
Moderator: General Moderators
Re: Date object problems
BBCode syntax tags, please!
NaN means "Not a Number". The time inputs have no value attributes, so on page load, their default values are empty strings. When the parseInt() function is given an empty string as input, it returns NaN.
I'm not sure what the rationale is for taking a string input and converting it into a number only to convert that number back into a string. Are you sure you need parseInt()?
If you want the default alarmtime to be...
NaN means "Not a Number". The time inputs have no value attributes, so on page load, their default values are empty strings. When the parseInt() function is given an empty string as input, it returns NaN.
I'm not sure what the rationale is for taking a string input and converting it into a number only to convert that number back into a string. Are you sure you need parseInt()?
If you want the default alarmtime to be...
- "NaN:NaN:NaN", do nothing.
- "::", remove the calls to parseInt().
- "0:0:0", add a value="0" attribute to each time input.
- something else, ask.