technocrawl
03-25-2012, 08:12 AM
I have wrote a code for some calculation that checks whether the RUN_time of an application falls between the Start_time and Stop_time, If it falls between the Start_time and Stop_time, then an alert with Success Message should popup else failure alert should popup.
I dont know what's the problem with the code, its not displaying the correct alert.
Can some experts deal with this and correct the code.
<html>
<head>
<script type="text/javascript">
function convert12to24(timeStr)
{
var meridian = timeStr.substr(timeStr.length-2).toLowerCase();
var hours = timeStr.substring(0, timeStr.indexOf(':'));
var minutes = timeStr.substring(timeStr.indexOf(':')+1);
return hours+':'+minutes;
}
//This function only for testing
function changeTimeFormat()
{
var input = document.getElementById('input').value
var twenny4hr = convert12to24(input);
//document.getElementById('output').value = twenny4hr;
var input_hr = twenny4hr.substring(0, twenny4hr.indexOf(':'));
var input_min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
if(input_hr >= 24)
{
alert('Hours should fall between 0:00 to 23:59');
softclose.input.value='';
}
if(input_min > 59)
{
alert('Minutes should fall between 00 to 59');
softclose.input.value='';
}
if(input_hr == 12)
{
var twelvehr = parseInt(input_hr);
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.';
}
else if(input_hr > 12 )
{
var twelvehr = parseInt(input_hr)-12;
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.';
}
else if(input_hr == 12 && input_hr == 0 || input_hr == 00 )
{
var twelvehr = parseInt(input_hr) + 12;
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.';
}
else
{
var twelvehr = parseInt(input_hr);
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.';
}
}
function changeTimeFormat1()
{
var t_bus_clndr_gmt = document.getElementById('t_bus_clndr_gmt').value
var twenny4hr = convert12to24(t_bus_clndr_gmt);
//document.getElementById('output1').value = twenny4hr;
var t_bus_clndr_gmt_hr = twenny4hr.substring(0, twenny4hr.indexOf(':'));
var t_bus_clndr_gmt_min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
if(t_bus_clndr_gmt_hr >= 24)
{
alert('Hours should fall between 0:00 to 23:59');
softclose.t_bus_clndr_gmt.value='';
}
if(t_bus_clndr_gmt_min > 59)
{
alert('Minutes should fall between 00 to 59');
softclose.t_bus_clndr_gmt.value='';
}
if(t_bus_clndr_gmt_hr == 12)
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr);
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.';
}
else if(t_bus_clndr_gmt_hr > 12 )
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr)-12;
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.';
}
else if(t_bus_clndr_gmt_hr == 12 && t_bus_clndr_gmt_hr == 0 || t_bus_clndr_gmt_hr == 00 )
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr) + 12;
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.';
}
else
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr);
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.';
}
//EST Format
var min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
var esthour = parseInt(twenny4hr)-4;
if(esthour > 12)
{
document.getElementById('EST').value = esthour + ':' + parseInt(min);
}
else if(esthour < 0)
{
document.getElementById('EST').value = esthour + 12 + ':' + parseInt(min);
}
else
{
document.getElementById('EST').value = esthour + ':' + parseInt(min);
}
}
function open_close_window()
{
var est = document.getElementById('EST').value;
var min = est.substring(est.indexOf(':')+1);
var ow = document.getElementById('open_window').value;
var cw = document.getElementById('close_window').value;
var est_hour = est.substring(0, est.indexOf(':'));
var start_time = parseInt(est_hour - ow);
var stop_time = parseInt(est_hour) + parseInt(cw);
document.getElementById('start_t').value = start_time + ':' + parseInt(min);
document.getElementById('end_t').value = stop_time + ':' + parseInt(min);
}
function check1()
{
var user_req_time = document.getElementById('input').value;
var user_req_hours = user_req_time.substring(0, user_req_time.indexOf(':'));
var start_time1 = document.getElementById('start_t').value;
var start_hours = start_time1.substring(0, start_time1.indexOf(':'));
var stop_time1 = document.getElementById('end_t').value;
var stop_hours = stop_time1.substring(0, stop_time1.indexOf(':'));
if(start_hours < user_req_hours )
{
flag = 0;
}
else
{
flag=1;
}
if(stop_hours > user_req_hours)
{
flag1 = 0;
}
else
{
flag1=1;
}
if(flag == 0 && flag1 ==0)
{
alert('success');
}
else
{
alert('failure');
}
}
</script>
</head>
<body>
<form name="softclose">
<table>
<tr>
<td>
User Requirement [24 hr format] : </td>
<td> <input type="text" name="input" id="input" onkeyup="changeTimeFormat();"> EST </td>
<td>
12Hr Output : </td><td> <input type="text" name="output" id="output"></td>
</tr>
<tr>
<td>
TBUS_CLNDR DB Time [24 hr format] : </td>
<td><input type="text" name="t_bus_clndr_gmt" id="t_bus_clndr_gmt" onkeyup="changeTimeFormat1();"> GMT </td>
<td>
12Hr Output : </td>
<td><input type="text" name="output1" id="output1">
</td>
</tr>
<tr>
<td width=200> Open Window </td>
<td width=120 colspan=2><input type='text' name="open_window" id='open_window' size=5 onkeyup="open_close_window();"//> Hrs </td>
</tr>
<tr>
<td width=200> Close Window </td>
<td width=120 colspan=2><input type='text' name="close_window" id='close_window' size=5 onkeyup="open_close_window();"/> Hrs </td>
</tr>
</table>
<br><br><br>
<table>
<tr>
<td width=200> EST Format: </td>
<td ><input type="text" name="EST" id="EST" value="" > EST</td>
</tr>
<tr>
<td width=200> Start Time: [24 hr format]</td>
<td ><input type="text" name="start_t" id="start_t" value="" ></td>
</tr>
<tr>
<td width=200> End Time: [24 hr format]</td>
<td><input type="text" name="end_t" id="end_t" value="" ></td>
</tr>
<tr>
<td align=center>
<input type=button name=check id=check value=check onclick="check1();">
</td>
</tr>
<table>
</form>
</body>
</html>
I dont know what's the problem with the code, its not displaying the correct alert.
Can some experts deal with this and correct the code.
<html>
<head>
<script type="text/javascript">
function convert12to24(timeStr)
{
var meridian = timeStr.substr(timeStr.length-2).toLowerCase();
var hours = timeStr.substring(0, timeStr.indexOf(':'));
var minutes = timeStr.substring(timeStr.indexOf(':')+1);
return hours+':'+minutes;
}
//This function only for testing
function changeTimeFormat()
{
var input = document.getElementById('input').value
var twenny4hr = convert12to24(input);
//document.getElementById('output').value = twenny4hr;
var input_hr = twenny4hr.substring(0, twenny4hr.indexOf(':'));
var input_min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
if(input_hr >= 24)
{
alert('Hours should fall between 0:00 to 23:59');
softclose.input.value='';
}
if(input_min > 59)
{
alert('Minutes should fall between 00 to 59');
softclose.input.value='';
}
if(input_hr == 12)
{
var twelvehr = parseInt(input_hr);
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.';
}
else if(input_hr > 12 )
{
var twelvehr = parseInt(input_hr)-12;
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'P.M.';
}
else if(input_hr == 12 && input_hr == 0 || input_hr == 00 )
{
var twelvehr = parseInt(input_hr) + 12;
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.';
}
else
{
var twelvehr = parseInt(input_hr);
document.getElementById('output').value = twelvehr + ':' + parseInt(input_min) + ' ' + 'A.M.';
}
}
function changeTimeFormat1()
{
var t_bus_clndr_gmt = document.getElementById('t_bus_clndr_gmt').value
var twenny4hr = convert12to24(t_bus_clndr_gmt);
//document.getElementById('output1').value = twenny4hr;
var t_bus_clndr_gmt_hr = twenny4hr.substring(0, twenny4hr.indexOf(':'));
var t_bus_clndr_gmt_min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
if(t_bus_clndr_gmt_hr >= 24)
{
alert('Hours should fall between 0:00 to 23:59');
softclose.t_bus_clndr_gmt.value='';
}
if(t_bus_clndr_gmt_min > 59)
{
alert('Minutes should fall between 00 to 59');
softclose.t_bus_clndr_gmt.value='';
}
if(t_bus_clndr_gmt_hr == 12)
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr);
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.';
}
else if(t_bus_clndr_gmt_hr > 12 )
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr)-12;
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'P.M.';
}
else if(t_bus_clndr_gmt_hr == 12 && t_bus_clndr_gmt_hr == 0 || t_bus_clndr_gmt_hr == 00 )
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr) + 12;
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.';
}
else
{
var twelvehr = parseInt(t_bus_clndr_gmt_hr);
document.getElementById('output1').value = twelvehr + ':' + parseInt(t_bus_clndr_gmt_min) + ' ' + 'A.M.';
}
//EST Format
var min = twenny4hr.substring(twenny4hr.indexOf(':')+1);
var esthour = parseInt(twenny4hr)-4;
if(esthour > 12)
{
document.getElementById('EST').value = esthour + ':' + parseInt(min);
}
else if(esthour < 0)
{
document.getElementById('EST').value = esthour + 12 + ':' + parseInt(min);
}
else
{
document.getElementById('EST').value = esthour + ':' + parseInt(min);
}
}
function open_close_window()
{
var est = document.getElementById('EST').value;
var min = est.substring(est.indexOf(':')+1);
var ow = document.getElementById('open_window').value;
var cw = document.getElementById('close_window').value;
var est_hour = est.substring(0, est.indexOf(':'));
var start_time = parseInt(est_hour - ow);
var stop_time = parseInt(est_hour) + parseInt(cw);
document.getElementById('start_t').value = start_time + ':' + parseInt(min);
document.getElementById('end_t').value = stop_time + ':' + parseInt(min);
}
function check1()
{
var user_req_time = document.getElementById('input').value;
var user_req_hours = user_req_time.substring(0, user_req_time.indexOf(':'));
var start_time1 = document.getElementById('start_t').value;
var start_hours = start_time1.substring(0, start_time1.indexOf(':'));
var stop_time1 = document.getElementById('end_t').value;
var stop_hours = stop_time1.substring(0, stop_time1.indexOf(':'));
if(start_hours < user_req_hours )
{
flag = 0;
}
else
{
flag=1;
}
if(stop_hours > user_req_hours)
{
flag1 = 0;
}
else
{
flag1=1;
}
if(flag == 0 && flag1 ==0)
{
alert('success');
}
else
{
alert('failure');
}
}
</script>
</head>
<body>
<form name="softclose">
<table>
<tr>
<td>
User Requirement [24 hr format] : </td>
<td> <input type="text" name="input" id="input" onkeyup="changeTimeFormat();"> EST </td>
<td>
12Hr Output : </td><td> <input type="text" name="output" id="output"></td>
</tr>
<tr>
<td>
TBUS_CLNDR DB Time [24 hr format] : </td>
<td><input type="text" name="t_bus_clndr_gmt" id="t_bus_clndr_gmt" onkeyup="changeTimeFormat1();"> GMT </td>
<td>
12Hr Output : </td>
<td><input type="text" name="output1" id="output1">
</td>
</tr>
<tr>
<td width=200> Open Window </td>
<td width=120 colspan=2><input type='text' name="open_window" id='open_window' size=5 onkeyup="open_close_window();"//> Hrs </td>
</tr>
<tr>
<td width=200> Close Window </td>
<td width=120 colspan=2><input type='text' name="close_window" id='close_window' size=5 onkeyup="open_close_window();"/> Hrs </td>
</tr>
</table>
<br><br><br>
<table>
<tr>
<td width=200> EST Format: </td>
<td ><input type="text" name="EST" id="EST" value="" > EST</td>
</tr>
<tr>
<td width=200> Start Time: [24 hr format]</td>
<td ><input type="text" name="start_t" id="start_t" value="" ></td>
</tr>
<tr>
<td width=200> End Time: [24 hr format]</td>
<td><input type="text" name="end_t" id="end_t" value="" ></td>
</tr>
<tr>
<td align=center>
<input type=button name=check id=check value=check onclick="check1();">
</td>
</tr>
<table>
</form>
</body>
</html>