Jon F Robinson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJon F Robinson
ToMe
SubjectQuestion Regarding Days-In-Month-Validator
Date29 April 2009 00:17
Hello Mark,

           First I would like to say thank you for creating that site.  It's
a great contribution.  I have a question regarding modifying the script for
the Days-In-Month-Validtor, so it can include default options that just say:
Day, Month, or Year for the respective fields.  To better understand what I
mean, I would like to emulate what was done on [URL] when putting
in the "birthday" information on their homepage.  The default options are
"month" "day" "year".  If I were to just simply add these as options the
function will break.  Do you know how I could modify the script so it can
handle having these options?

 A little bit about myself: I currently know very little java script.  I
have recently learned html, PHP, and MySQL - however it became clear I would
need javascript at least in this instance because adjusting for leap years
and such would be impossible in PHP (at least to my understanding).  I did
not e-mail you immediately when I had the problem.  I've spent a day or two
reviewing your script and trouble shooting to figure it out myself because I
take pride in figuring it out on my own-- but it soon became clear its a
little over my head at the moment.  Some variables or functions I don't
quite understand because I don't know java but a lot of it is very similar
to the conditional loops used in PHP.  Even so its becoming clear that it
could take weeks to figure this out and I could use help from an expert.

Note: I also read your terms and conditions for using these scripts and plan
on following them exactly.  Thank you for your time.

Best,

Jon
FromMe
ToJon F Robinson
SubjectRe: Question Regarding Days-In-Month-Validator
Date3 May 2009 08:44
Jon,

Thanks for the nicely written support request.

> The default options are "month" "day" "year".
> Do you know how I could modify the script so it can
> handle having these options?

Sadly, it's not possible to do this in a clean way. The script
manipulates the numbers that are displayed all the time, and selecting
one could easily change the numbers that are displayed in another (for
example, when you select a month, it will change the number of days to
match that month). If the placeholder options appear at the top, they
will offset the count, and cause the wrong number of options to be
available.

Now in theory, you could create an impossible set of options, like for
example the year 3000, month 13, day 32, and give those the text you
desire, placing them at the bottom of the select inputs. This does seem
to work.

...
<option>31</option>
<option selected>Day</option>
</select>
...
<option>December</option>
<option selected>Month</option>
</select>
...
<option value="2009">2009</option>
<option selected value="3000">Year</option>
</select>

The Day placeholder will disappear as soon as a month is selected. The
Year placeholder will disappear as soon as "Higher..." or "Lower..." is
selected. The only bug I can see is that it gets very confused when the
year is changed without selecting a month first, or when the month is
changed back to the placeholder, because the month is too high, and it
cannot work out how many days it has. As a result, you would need to
make it automatically delete the Month placeholder when the year or
month are changed:

function deletePlaceHolder(name) {
name = MWJ_findSelect(name);
if( name.selectedIndex == 12 ) {
name.options[0].selected = true;
}
if( name.options.length > 12 ) {
name.options[12] = null;
}
}
...
<select name="year" size="1" onchange="
deletePlaceHolder('month');
dateChange('day','month','year');
">
...
<select name="year" size="1" onchange="
deletePlaceHolder('month');
checkMore( this, 1980, 2005, 1840, 2010 );
dateChange('day','month','year');
">

Hope this is clean enough for your needs.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.