How do I modify a dropdown box?

D

David Mark

Jukka said:
bruce wrote:

[ massive fullquote despite all the clues posted... ]
You are correct. The technical solution is simple. I have it working
with basically 4 lines of code.

For some odd values of "working", I gather from the URL. (That is, its
absence.)

I bet your code does not even address one of the technical issues I
mentioned: the number of days in February depends on the year, and your
scenario (to the small amount it was revealed) postulates that the year
is selected _after_ selecting month and day.

But I do accept the idea that you can make almost everything work in 4
lines of code in JavaScript. You might just need extraordinarily long
lines at times.

Yes, but "chaining" hundreds of method calls together is "elegant"
according to many JS "programmers". Copy, paste, chain, etc. It just
works. Well, except in the many cases where it doesn't but they don't
"care" about those cases.
 
J

John G Harris

Ben said:
[...]
But accept
2010-05-03
2010-5-3
2010/5/3
2010.5.3
as equally valid. (Unless you actively want to lose customers).

The other formats are nonstandard open to arbitrary interpretation.

Imagine you learnt to use '/' and no redundant zeroes at school and
you've been using this successfully for the last 40 years. Now imagine
some jumped up shopkeeper says you are wrong, wrong, wrong, because
computers can't understand it. Would you recommend that online shop to
your friends ?

As for being non-standard, you will find that the motive for producing
ISO 8601:2004 was to facilitate the sending of dates across national
boundaries. Also, to facilitate the sending of dates between computers.
It does not concern itself with letters sent to your Aunty Lily in
Australia, nor with letters sent by customers to shop keepers.

Although I am guessing here, it might be considered a liability of the
web site for providing an unauthorized credit card number that is not
what the user entered, where the user may claim that he did not enter
that number.

Nah! The programmers can't be bothered to handle spaces, *and* get it
right.

John
 
D

Dr J R Stockton

In comp.lang.javascript message <4a61d8ae-e333-4849-962a-9f68f7092b78@d1
9g2000yqf.googlegroups.com>, Tue, 4 May 2010 11:56:12, bruce
You are correct. The solution to my problem was easy. 4 lines of
code..

If you were to post that code,
either it might be helpful to others
or we could tell you of its faults.

<URL:http://www.merlyn.demon.co.uk/js-date6.htm> needs more than 4
lines, IIRC.

But the whole thing is much easier in HTML 5, where appropriately
implemented : <URL:http://www.merlyn.demon.co.uk/js-date3.htm#HTML>.
 
B

bruce

In comp.lang.javascript message <4a61d8ae-e333-4849-962a-9f68f7092b78@d1
9g2000yqf.googlegroups.com>, Tue, 4 May 2010 11:56:12, bruce
<[email protected]> posted:




If you were to post that code,
either    it might be helpful to others
or        we could tell you of its faults.

Sure. I'd be especially interested in its faults.

Invocation is via an onChange event
<snip>
<select name="month" id="month" size="1"
onchange="setDayBox(document.Reservation.month.options[document.Reservation.month.selectedIndex].value);">

/* ******************************************************** */
/* setDayBox */
/* Change the number of days in the Day drop down box to */
/* reflect the number of days in the selected month. */
/* Input argument: */
/* chosen: Selected month (1 to 12) */
/* ******************************************************** */

function setDayBox(chosen) {

var numberOfDays = selectNumberOfDaysInMonth(parseInt(chosen));

var dayBox = document.Reservation.Day;
dayBox.options.length = 0;

for(i=0; i < numberOfDays; i++) {

dayBox.options[dayBox.options.length] = new Option(i
+1,i,false,false);

}
}
 
G

Garrett Smith

[snip]

("snip" explained here said:
Sure. I'd be especially interested in its faults.

Invocation is via an onChange event
<snip>
<select name="month" id="month" size="1"
onchange="setDayBox(document.Reservation.month.options[document.Reservation.month.selectedIndex].value);">

Accessing form controls the nonstandard way, as you have, has known side
effects. The most obvious is that if the control is orphaned from the
document after it has been accessed off the form, it remains as a
property of the form, even if there are no other references pointing to it.

To correctly access a form control, please see:
/* ******************************************************** */
/* setDayBox */
/* Change the number of days in the Day drop down box to */
/* reflect the number of days in the selected month. */
/* Input argument: */
/* chosen: Selected month (1 to 12) */
/* ******************************************************** */

function setDayBox(chosen) {

var numberOfDays = selectNumberOfDaysInMonth(parseInt(chosen));

It is a good idea to be in the habit of using a radix with parseInt.

var dayBox = document.Reservation.Day;
dayBox.options.length = 0;

for(i=0; i < numberOfDays; i++) {

Don't forget var.
dayBox.options[dayBox.options.length] = new Option(i
+1,i,false,false);

}
}

The strategy employed sets dayBox to numberOfDays each time a month is
selected. That is not a very efficient approach.

Instead, when the selected month contains less than 31 days, why not
disable the days from the end of the month. That way a js-disabled user
(such as myself), has the ability to use it.

Rough outline:

// untested.
function adjustDaysForDate(selectedMonth, selectedYear) {
var daysInMonth = getDaysInMonth(selectedMonth, selectedYear);
var disabledDays = 31 - daysInMonth;
if(disabledDays) {
disableInvalidDays(disabledDays);
}
}

function disableInvalidDays(count) {
for(var i = 0; i < count; i++) {
daySelectElement.options[30-i].disabled = true;
}
}

function getDaysInMonth(month, year) {
// etc.
}
[snip]

[snip Stockton's sig]
 
B

bruce

[snip]

("snip" explained here said:
Sure. I'd be especially interested in its faults.
Invocation is via an onChange event
<snip>
<select name="month" id="month" size="1"
onchange="setDayBox(document.Reservation.month.options[document.Reservation.month.selectedIndex].value);">

Accessing form controls the nonstandard way, as you have, has known side
effects. The most obvious is that if the control is orphaned from the
document after it has been accessed off the form, it remains as a
property of the form, even if there are no other references pointing to it.

To correctly access a form control, please see:
/* ******************************************************** */
/* setDayBox                                                */
/*    Change the number of days in the Day drop down box to */
/*    reflect the number of days in the selected month.     */
/* Input argument:                                          */
/*    chosen: Selected month (1 to 12)                      */
/* ******************************************************** */
function setDayBox(chosen) {
  var numberOfDays = selectNumberOfDaysInMonth(parseInt(chosen));

It is a good idea to be in the habit of using a radix with parseInt.

  var dayBox = document.Reservation.Day;
  dayBox.options.length = 0;
  for(i=0; i < numberOfDays; i++) {

Don't forget var.
     dayBox.options[dayBox.options.length] = new Option(i
+1,i,false,false);

The strategy employed sets dayBox to numberOfDays each time a month is
selected. That is not a very efficient approach.

Instead, when the selected month contains less than 31 days, why not
disable the days from the end of the month. That way a js-disabled user
(such as myself), has the ability to use it.

Rough outline:

// untested.
function adjustDaysForDate(selectedMonth, selectedYear) {
   var daysInMonth = getDaysInMonth(selectedMonth, selectedYear);
   var disabledDays = 31 - daysInMonth;
   if(disabledDays) {
     disableInvalidDays(disabledDays);
   }

}

function disableInvalidDays(count) {
   for(var i = 0; i < count; i++) {
     daySelectElement.options[30-i].disabled = true;
   }

}

function getDaysInMonth(month, year) {
   // etc.}

[snip]

[snip Stockton's sig]

Garrett:

Thanks for the "education." I will use what you have suggested, once
I understand it.

Thanks again..

Bruce
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
8924D9443D28E23ED5CD>, Wed, 5 May 2010 15:04:33, John G Harris
As for being non-standard, you will find that the motive for producing
ISO 8601:2004 was to facilitate the sending of dates across national
boundaries. Also, to facilitate the sending of dates between computers.
It does not concern itself with letters sent to your Aunty Lily in
Australia, nor with letters sent by customers to shop keepers.


The utility of a standard format is not limited to the original motives
for creating it. That standard is not computer-specific (except for
presuming that a computer is needed to read the PDF).

The standard form is beneficial in weak contexts, where it is readily
recognisable as a probable date. Consider dates on tinned food, where
day-of-month may be omitted and there is usually a reference number of
arbitrary form nearby.

If a recovering American wrote in March to complain that he got food
poisoning on 2/4/10 at your jellied eel stand, you'd not get away with
rejecting the claim that your shop will be closed then because it will
be Good Friday.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top