Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm trying to let a user enter a ti

Status
Not open for further replies.

faiyth

Programmer
Nov 22, 2002
19
US
I'm trying to let a user enter a time (Such as 07:00:00) then, run my javascript so that I can look at that time. At this point it will confirm the time with the user.. then If the time entered is between 7am and 6pm on a monday through Friday I want to pop up an extra "Are you sure?" Right now I'm just trying to get the time to work, then I'll move on to the day of the week part. heh. I'm having the hardest time getting the time to be seen as a date.. any help would be greatly appreciated.

function confirmsubresults() {
var my_begintime=new Date("07:00:00");
var my_endtime=new Date("18:00:00");
var my_enteredtime= new Date(document.mim.f_mac.value);
if (confirm("Are you sure you want to schedule for " +my_enteredtime+ "?"))
if (my_enteredtime<=my_begintime && my_enteredtime>=my_endtime) {
return true;
} else {
if (confirm(&quot;The time you have scheduled for is between the hours of 7am and 6pm, are you absolutely sure you want to schedule for this time frame?&quot;))
return true;
else {
return false;
} } else {
return false;
} }


HTML
<form name=&quot;mim&quot; onsubmit=&quot;return confirmsubresults();&quot;>
<input type=&quot;text&quot; name=f_mac onblur=&quot;javascript: return document.mim.f_mac.length&quot;>
<input type=&quot;text&quot; name=f_mac1 value=&quot;&quot;>
<input type=submit name=submit value=submit>
</form>
 
bit of advice! try formatting your code so it can be read. [wink]

the new date() function doesn't quite work that way. I know times are irritating in javascript
I did not look at your conditional statement but I can see a few missing } { etc... if you format your code properly or even just broken up a bit you can catch those much easier

try this
<html>
<head>
<script>
function confirmsubresults() {
var my_begintime=new Date();
my_begintime = &quot;07:00:00&quot;;
alert(my_begintime);
var my_endtime=new Date();
my_endtime = &quot;18:00:00&quot;
alert(my_endtime);

var my_enteredtime = new Date();
my_enteredtime = document.mim.f_mac.value
alert(my_enteredtime);

if (confirm(&quot;Are you sure you want to schedule for &quot; +my_enteredtime+ &quot;?&quot;))
if (my_enteredtime<=my_begintime && my_enteredtime>=my_endtime) {
return true;
} else {
if (confirm(&quot;The time you have scheduled for is between the hours of 7am and 6pm, are you absolutely sure you want to schedule for this time frame?&quot;))
return true;
else {
return false;
}
} else {
return false;
}
}
</script>
</head>
<body>


<form name=&quot;mim&quot; onsubmit=&quot;return confirmsubresults();&quot;>
<input type=&quot;text&quot; name=f_mac onblur=&quot;javascript: return document.mim.f_mac.length&quot;>
<input type=&quot;text&quot; name=f_mac1 value=&quot;&quot;>
<input type=submit name=submit value=submit>
</form>
</body> onpnt
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Hehe! Sorry, i'm absolutely frustrated. So of course my code is messy.. I've written it cleaned then spent 2 and a half hours deleting, adding and changing things.. so my code just gets uglier and uglier.. But I'm still having the same problem with your helpful code. Whether the user enters 06:00:00 or 17:01:00 no matter what it isn't seeing the time. It's ALWAYS telling me that the entry is between the 7am and 8pm time frame. Which of course is wrong. 18:00:00 is more then 17:00:00 in time.. so I'm still frustrated. Oh well..
 
it looks like you're just trying to put too much logic into not a whole lot of logic. [smile]

when you write nested if statements as you are you need to really step back and look at what you're doing with the main thing that is going to write your script. &quot;suedocode&quot;
I know this seems to have left programmers but I still write seuod for everything I do. no matter how small. I'm sorry if this sems dictatorship but I'm just being honest with you.

so what you want is a confrim no matter what
on true confirm if GREATER then begin time and LESS then end time
confirm again for assurance
if true confirm then
return submission
else return false and stop submission

notice a bit of changes in your logic if > to <
that I think is your main fault here.
ok, so lets turn it into code
//if confirm entry
if (confirm(&quot;Are you sure you want to schedule for &quot; +my_enteredtime+ &quot;?&quot;))
//if values are between my times
if (my_enteredtime>=my_begintime && my_enteredtime<=my_endtime) {
// confirm again for assurance
if (confirm(&quot;The time you have scheduled for is between the hours of 7am and 6pm, are you absolutely sure you want to schedule for this time frame?&quot;)) {
//if confirm is true return submit
return true;
}
else
{
//else cancel
return false;
}
}
}


and there we have it. I think anyways. [smile]
try it out and see if that is what you are trying to accomplish onpnt
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top