PDA

View Full Version : checking between two drop down list boxes.


scriptblur
10-29-2002, 08:30 AM
hi guys.... Please help.....

how can i do a checking in either javascript or VBscript for two drop down list boxes. Example i got Start time and End time for the two drop down list boxes.... both the times will be pass to the next page in "Request.Form". The start time can never be greater value than the End time, if the start time is greater, an error box will be prompt to the user. does anyone know how to do it???? Please help... thank... a lot.


Example the start time is 1300 and the end time can never be 1200... it must be later than the start time(1300)...

raf
10-29-2002, 09:02 AM
(VBscript)
2 action :
- compare the values
- display the message

for comparing : you don't indicate what kind a value this is and how you get it. so we need more info on that to help you. are the dates selected from the menu's ? or thay in dateformat ? you'll always have to compare them.
You can use a DateDiff function to compare two dates and compute the interval or you can just convert them and compare them.

your code will always look like :


dim date1, date2
date1=request.form("date1")
date2=request.form("date2")

if date1 > date 2 then
response.write("<font color='red'>NO WAY YOUR GOING TO ENTER THOSE DATES</font>")
else
response.write("OK. Datevalidation passed")
end if


in stead of a response;write, you can use a redirect etc

scriptblur
10-30-2002, 02:09 AM
hi raf,, thank...
i know this method can work...

but what i want is instead of response.write the error message, it prompt a error message box that may be in javascipt or vbscript.... do u have a better view??

i have tested it but i think it does really check the condition (if date1 > date 2 then)...

whammy
10-30-2002, 03:15 AM
Actually, you need to look up the DateDiff() function. That is what you need to figure out.

Check out my signature... (hint... look up DateDiff() on google!).

That will do everything you are looking for, almost. :)

Of course you can always write some javascript to the page to alert someone if you've determined they have entered incorrect data... I'd make sure you've looked at the function above first though.

If you need some examples, I can provide you with them within a couple of days... but here's a hint:

Check the "start" date with IsDate() - and make sure it's valid. If not then throw an error.

Then Check the "end" date with IsDate() - and make sure it's valid. If not then throw an error.

Then once you are sure they are both actually dates, you can run the DateDiff() function on them (the reason I say this, is because if you try to use DateDiff and one of the dates is not valid, it will error on you).

Hope this helps!

scriptblur
10-30-2002, 06:18 AM
hi whammy... thank for the guidances... it will be perfect if u could show me some examples...

by the way... i am checking for time (mention on my first post) and not date... can the DateDiff() , IsDate functions work on time as well????

whammy
10-31-2002, 12:16 AM
Yes. :)

If you need examples, the best place to look for them is probably on:

http://www.w3schools.com/

However, I have a great example for you, I'll see if I can find it.

:D

Mhtml
10-31-2002, 12:40 AM
DateDiff(interval, date1, date2)

The datediff() can contain Hours Minutes and Seconds to evaluate the difference between to dates,

example:

<%Function DiffADate()
DiffADate = DateDiff("h", now,02012003)
End Function
Response.write(DiffADate)
%>


This displays the difference in time between now and 02/01/03

How DateDiff() can be implmented into your situation, I don't know.
Whammy why?:confused:

whammy
10-31-2002, 12:47 AM
Well, say for instance you want to give someone a report (a client, for instance) of every record in the database that was entered between two dates.

Then you can make a form (like the date.zip file I posted recently, but with TWO different date dropdowns), which lets the client select a date range, i.e. "I want to see everything that was entered into the database between 1/1/2002 and today's date".

The client changes the dates to the appropriate date range, and then you post the results back to the same page (or another page if that's your preference), and then you need to compare them to see:

1. They selected a valid date. i.e. 2/31/AnyYear is invalid, since February only has 28-29 days (29 only on a leap year). For that you use IsDate().

2. The second date they selected is also a valid date (IsDate() again).

3. Once you've determined that they are both valid dates, and the second date isn't earlier than the first (which you can determine using DateDiff()), then you can display all the results BETWEEN those dates that exist in the database. Of course then you need to check of rs.EOF to see if any DO exist. :)

Does that help? ;)