Checking Select Option Value Without Form Submital

7

75battle

I am allowing a user to selected a date to schedule an event and it
seems like the best way to do this is with drop down menus for Year,
month, date. However I would like to make it so when you choose a year
and a month the appropriate days for that month show (i.e. 28 days if
you chose February 2006). I can easily do this with a loop if I can
find out what month the user has selected, but I can't seem to find a
way to get that value. Is there a simple javascript solution to this
problem?
 
V

VK

I am allowing a user to selected a date to schedule an event and it
seems like the best way to do this is with drop down menus for Year,
month, date. However I would like to make it so when you choose a year
and a month the appropriate days for that month show (i.e. 28 days if
you chose February 2006). I can easily do this with a loop if I can
find out what month the user has selected, but I can't seem to find a
way to get that value. Is there a simple javascript solution to this
problem?

<select name="myMonthList"
onchange="setBestDay(this.form, this.selectedIndex)">
<option value="0">January</option>
...
</select>

where in the <head> section you have:

<script type="text/javascript">
function setBestDay(f,m) {
// m corresponds to the selected month
// 0 - January, 11 - December
// do your calculations
// then:
f.myDayList.selectedIndex = myCalculatedIndex;
}
</script>
 
T

TheBagbournes

I am allowing a user to selected a date to schedule an event and it
seems like the best way to do this is with drop down menus for Year,
month, date.

No it bloody isn't! I *hate* having to go through the click, scroll
select 3 times!

Have an input field with flexible validation, and a popup calendar for
those who *must* use their mouse. There are plenty of open source
examples out there.
 
R

RobG

TheBagbournes said:
No it bloody isn't! I *hate* having to go through the click, scroll
select 3 times!

Have an input field with flexible validation, and a popup calendar for
those who *must* use their mouse. There are plenty of open source
examples out there.

Complete agreement.
 
R

Richard Cornford

VK said:
(e-mail address removed) wrote:
<select name="myMonthList"
onchange="setBestDay(this.form, this.selectedIndex)">
<option value="0">January</option>
...
</select>

where in the <head> section you have:

<script type="text/javascript">
function setBestDay(f,m) {
// m corresponds to the selected month
// 0 - January, 11 - December
// do your calculations
// then:
f.myDayList.selectedIndex = myCalculatedIndex;
}
</script>

Don't be silly, it makes absolutely no sense what so ever to select a
day of the month for the user in response to the user selecting a month
and a year.

Richard.
 
V

VK

Anyone reading OP's text in this newsgroup besides me? The spelled task
was to *suggest* a day *based on the selected year and month*. Read it
again... then again... then again... bingo! (or not yet?)

:)
 
R

Richard Cornford

VK said:
Anyone reading OP's text in this newsgroup besides me? The spelled
task was to *suggest* a day *based on the selected year and month*.
Read it again... then again... then again... bingo! (or not yet?)

The OP's specified requirement was to alter the number of days available
for selection as options to correspond with the number of days available
in the selected month in the selected year. It makes no sense at all
'suggest' a day selection based on the selection of a month or a year.
Try reading it yourself, and again try to understand that when your
interpretation of something differs from everyone else's the odds are
that it is you who is wrong.

Richard.
 
R

Richard Cornford

VK said:
Anyone reading OP's text in this newsgroup besides me? The spelled
task was to *suggest* a day *based on the selected year and month*.
Read it again... then again... then again... bingo! (or not yet?)

The OP's specified requirement was to alter the number of days available
for selection as options to correspond with the number of days available
in the selected month in the selected year. It makes no sense at all
'suggest' a day selection based on the selection of a month or a year.
Try reading it yourself, and again try to understand that when your
interpretation of something differs from everyone else's the odds are
that it is you who is wrong.

Richard.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Sun, 5 Feb 2006 13:41:01 remote, seen in
news:comp.lang.javascript said:
<select name="myMonthList"
onchange="setBestDay(this.form, this.selectedIndex)">
<option value="0">January</option>
...
</select>

where in the <head> section you have:

<script type="text/javascript">
function setBestDay(f,m) {
// m corresponds to the selected month
// 0 - January, 11 - December
// do your calculations
// then:
f.myDayList.selectedIndex = myCalculatedIndex;
}
</script>

There is much to be said for understanding a question before attempting
to give an answer - you should try it sometime.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Sun, 5 Feb 2006 12:47:13 remote, seen in
I am allowing a user to selected a date to schedule an event and it
seems like the best way to do this is with drop down menus for Year,
month, date.

It isn't, at least for users of normal intelligence.
However I would like to make it so when you choose a year
and a month the appropriate days for that month show (i.e. 28 days if
you chose February 2006). I can easily do this with a loop if I can
find out what month the user has selected, but I can't seem to find a
way to get that value. Is there a simple javascript solution to this
problem?

I don't know. There is a javascript solution, but I don't know whether
it would be right to call it simple.

Before posting to a newsgroup, one should seek and study its FAQ. That
would have led you not only to code that does just what you ask for, but
also to reasons against using drop-downs for date. See below.

Note that if a page is intended to be usable without javascript, then
the day-of-month element must be loaded with 1..31 by HTML.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Sun, 5 Feb 2006 23:44:31 remote, seen in
news:comp.lang.javascript said:
Anyone reading OP's text in this newsgroup besides me? The spelled task
was to *suggest* a day *based on the selected year and month*. Read it
again... then again... then again... bingo! (or not yet?)

We already have discovered that you do not understand programming, and
that you cannot write proper English.

Now we have convincing evidence that you cannot understand (almost)
proper English.

Are there no EFL classes in your area? Could you not start a javascript
newsgroup in a hierarchy for your mother-tongue?
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top