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=documen t.choice.FirstC h.value
SecondCh=docume nt.choice.Secon dCh.value
FirstCh=documen t.choice.FirstC h.value
function makeArray2() {
var args = makeArray1.argu ments;
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(da te.getTime() - skew);
}
function getString2(date ) {
var months = new makeArray2("Jan uary", "February", "March",
"April", "May", "June",
"July", "August", "September" ,
"October", "November", "December") ;
return months[date.getMonth()] + " " +
(date.getDate() + 2) + ", " +
date.getFullYea r() + "," + " ";
}
var cur2 = new Date();
fixDate2(cur2);
var today2 = getString2(cur2 );
var fCD = FirstCh.substri ng (FirstCh.indexO f (">"),
FirstCh.indexOf ("("));
if (fCD == today2) {
alert("Delivery date choice must be at least two days from today.")
document.laptop .FirstCh.focus( )
return false
} 1 1840
JRS: In article <11************ **********@y43g 2000cwc.googleg roups.com>
, dated Thu, 8 Jun 2006 11:51:33 remote, seen in
news:comp.lang. javascript, joeyej <jo************ *@quinnipiac.ed u>
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=docume nt.choice.First Ch.value SecondCh=docum ent.choice.Seco ndCh.value
FirstCh=docume nt.choice.First Ch.value
Superfluous.
function makeArray2() { var args = makeArray1.argu ments;
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(da te.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("Jan uary", "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.getFullYea r() + "," + " "; } var cur2 = new Date(); fixDate2(cur2) ; var today2 = getString2(cur2 );
var fCD = FirstCh.substri ng (FirstCh.indexO f (">"), FirstCh.indexO f("(")); if (fCD == today2) { alert("Deliver y date choice must be at least two days from today.") document.lapto p.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.get Date()+1)
for (D.setDate(D.ge tDate()+2), N=0; N<22; D.setDate(D.get Date()+1), N++)
if (D.getDay()%6!= 0) document.writel n(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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 adresses and so on.
I thought it might be a better way to programm an automated, dynamic
form validation that works for all kinds of fields, shows the
necessary error messages and highlights the coresponding form fields.
|
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 script is run and only
if the date is correct is the form submited.
What i have done so far is:
-Chagned the button type from 'submit' to 'button'
|
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 am expecting.
Can anyone help please
TIA
Steve
PS I'm new to javascript
|
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 certain fields match certain
criteria, and inform the user in different ways when the data is wrong
(offcourse, this will be checked on posting the data again, but that's
something I've got a lot of experience with).
Now, offcourse it's...
|
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,
convert.ToDatetime etc fail on the US date format as the application and IIS
is set to UK format.
Its strange that the date format("12/03/06","MM dd yy") is interpretated
correctly but format("12/22/06","MM dd yy") bombs out.
| |
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 form the
control is on?
Basically I have a number of controls in a form that are required, and
to check it I am setting the Validation Rule to "<>"IsNull" so that
when the user tries to tab through/click out of a required area
without entering...
|
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
|
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 "Datetime.TryParse()" a good choice?
Thanks
|
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 that are SELECT elements (javascript-- one named arrivalcity and one named returncity). Basically they ask for a departure and return city and another menu appears with options based on that city. I can't seem to get the input from these fields in the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |