473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form date choice validation

I'm using this code to make sure users are unable to choose a date from
a drop list (<option value="June 8, 2006, (Thursday), 9am">June 12,
2006, (Thursday), 9am) that is less than two days out from the system
date. How can I improve it to be sure weekends are excluded? I also
need to make sure end of month/begin new month is included in choices
being at least 2 days away from system date - . Any help is
appreciated.

Thanks, Joe

FirstCh=document.choice.FirstCh.value
SecondCh=document.choice.SecondCh.value

FirstCh=document.choice.FirstCh.value

function makeArray2() {
var args = makeArray1.arguments;
for (var i = 0; i < args.length; i++) {
this[i] = args[i];
}
this.length = args.length;
}

function fixDate2(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

function getString2(date) {
var months = new makeArray2("January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December");
return months[date.getMonth()] + " " +
(date.getDate() + 2) + ", " +
date.getFullYear() + "," + " ";
}
var cur2 = new Date();
fixDate2(cur2);
var today2 = getString2(cur2);

var fCD = FirstCh.substring (FirstCh.indexOf (">"),
FirstCh.indexOf("("));
if (fCD == today2) {
alert("Delivery date choice must be at least two days from today.")
document.laptop.FirstCh.focus()
return false
}

Jun 8 '06 #1
1 1817
JRS: In article <11**********************@y43g2000cwc.googlegroups .com>
, dated Thu, 8 Jun 2006 11:51:33 remote, seen in
news:comp.lang.javascript, joeyej <jo*************@quinnipiac.edu>
posted :
I'm using this code to make sure users are unable to choose a date from
a drop list (<option value="June 8, 2006, (Thursday), 9am">June 12,
2006, (Thursday), 9am) that is less than two days out from the system
date.
Then put only acceptable dates in the list, if you can assume javascript
is enabled or if the page is generated by server code. And June 12 is
expected to be a Monday.

"Two days out" is unclear - is it inclusive or exclusive, forwards or
backwards or both? If an order is placed on Monday at 23:59, is it
reasonable to promise the same delivery as for an order placed on Monday
at 00:01? What if the customer is in a different time zone to the
supplier?

How can I improve it to be sure weekends are excluded?
You must first define "weekend"; it varies between countries and
religions.
I also
need to make sure end of month/begin new month is included in choices
being at least 2 days away from system date - . Any help is
appreciated. FirstCh=document.choice.FirstCh.value
SecondCh=document.choice.SecondCh.value

FirstCh=document.choice.FirstCh.value
Superfluous.

function makeArray2() {
var args = makeArray1.arguments;
makeArray1 is not known.
for (var i = 0; i < args.length; i++) {
this[i] = args[i];
}
this.length = args.length;
}
The function seems pointless; what do you intend it to do, and why do
you think that is needed?
function fixDate2(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
(a) you are not allowing for skew possibly being negative?
(b) skew will always be zero.
function getString2(date) {
var months = new makeArray2("January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December");
You only need var months = ['Jan', ..., 'Dec']
return months[date.getMonth()] + " " +
(date.getDate() + 2) + ", " +
date.getFullYear() + "," + " ";
}
var cur2 = new Date();
fixDate2(cur2);
var today2 = getString2(cur2);

var fCD = FirstCh.substring (FirstCh.indexOf (">"),
FirstCh.indexOf("("));
if (fCD == today2) {
alert("Delivery date choice must be at least two days from today.")
document.laptop.FirstCh.focus()
return false
}


Before writing javascript, you should first learn something about it.
Before coding for dates, you should first learn something about the
facilities provided in the language.
Code should be indented to show structure.
Comment is important in non-working code, as it can show intent.
ISTM that you should have paid more attention in your classes.

This will show a list of future dates matching the criteria within a
given number of days; to get a list of given length, move N++ -

D = new Date() // if (D.getHours()>=12) D.setDate(D.getDate()+1)
for (D.setDate(D.getDate()+2), N=0; N<22; D.setDate(D.getDate()+1), N++)
if (D.getDay()%6!=0) document.writeln(D, '<br>')

You will need to format that date and to add it to the options array of
the selector - see js-date7.htm#WeDA .

Read the newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
1
by: Lukelrc | last post by:
Hi, I have a form containing (among other things) date fields for which i have a date validation script. What i need to happen is when the user presses the submit button the date validation...
14
by: Steve Wright | last post by:
I am trying to validate if an entry on a form is a date. I have adapted code I found here http://www.codingforums.com/archive/index.php/t-14325 as below but I can't seem the get the results that I...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
6
by: NH | last post by:
I want to allow users to enter dates in a text box in either the US "MM dd yy" format or the UK "dd MM yy" format. But how can I validate these dates? All the date functions e.g. ISdate,...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
5
by: maz77 | last post by:
I'm trying to develop a good validation for a date in C#; a valid date can be inserted in these formats: - dd/mm/yyyy - dd/mm/yyyy h24:m - mm/dd/yyyy - mm/dd/yyyy h12:m How can I proceed? Is...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.