I have 3 combo boxes inside the html page where in I take the year
,month and day .Now I want that by default in the month combobox
current month should be default (selected).Similarly in the day
combobox Today's date should be default selected and tommorow it should
change to the tommorows date . Like wise in the year combo box.

For example today is september 13 2006.

So when he opens the page the combo boxes should display 13 September
2006 .

Now if he wants he can choose from the other dates months and years.
its done by giving SELECTED keyword in the option tag ,but in this case
selected date has to change daily.So do I need to write some script?

Thanks
Divya

Re: How can a Combobox option the one which is the default selected change based on today's date? by Walter

Walter
Wed Sep 13 12:12:05 CDT 2006


"divya" <divya_sanam@yahoo.com> wrote in message
news:1158142765.587035.116350@e3g2000cwe.googlegroups.com...
:I have 3 combo boxes inside the html page where in I take the year
: ,month and day .Now I want that by default in the month combobox
: current month should be default (selected).Similarly in the day
: combobox Today's date should be default selected and tommorow it should
: change to the tommorows date . Like wise in the year combo box.
:
: For example today is september 13 2006.
:
: So when he opens the page the combo boxes should display 13 September
: 2006 .
:
: Now if he wants he can choose from the other dates months and years.
: its done by giving SELECTED keyword in the option tag ,but in this case
: selected date has to change daily.So do I need to write some script?
:
: Thanks
: Divya
:

Here's a working example that also automatically adjusts the number of days
in the day combo box if the year or month changes.

<html>
<head>
<title>Select Date Test</title>
<script type='text/vbscript'>
Sub Window_Onload()
Dim CurDate
CurDate = Now
CurDate = Array(Year(CurDate),Month(CurDate),Day(CurDate))
AddOptions Form1.Year,CurDate(0) - 15,CurDate(0) + 15,CurDate(0)
AddOptions Form1.Month,1,12,CurDate(1)
AddOptions Form1.Day,1,31,CurDate(2)
End Sub

Sub AddOptions(Sel,Start,Finish,Index)
Dim Count
For Count = Start To Finish
Sel.Add Window.Option(Count,Count)
If Count = Index Then Sel.SelectedIndex = Sel.Length - 1
Next
End Sub

Sub ChangeDay(YearValue,MonthValue)
Dim Length
Dim Count
Dim Sel
Set Sel = Form1.Day
Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
If Length = 0 Then Length = 31
If Sel.Length > Length Then
Sel.Length = Length
ElseIf Sel.Length < Length Then
For Count = Sel.Length + 1 To Length
Sel.Add Window.Option(Count,Count)
Next
End If
End Sub
</script>
</head>

<body>
<form name='form1'>
<select name='year' onchange='changeDay me.value,me.form.month.value'>
</select>
<select name='month' onchange='changeDay me.form.year.value,me.value'>
</select>
<select name='day'></select>
</form>
</body>
</html>




Re: How can a Combobox option, the one which is the default selected change based on today's date? by divya

divya
Thu Sep 14 01:51:48 CDT 2006

Hiiii,
This example works exactly the way I want.Thanks,Thanks ,Thanks
a lot .
Regards,
Divya.


Walter Zackery wrote:
> "divya" <divya_sanam@yahoo.com> wrote in message
> news:1158142765.587035.116350@e3g2000cwe.googlegroups.com...
> :I have 3 combo boxes inside the html page where in I take the year
> : ,month and day .Now I want that by default in the month combobox
> : current month should be default (selected).Similarly in the day
> : combobox Today's date should be default selected and tommorow it should
> : change to the tommorows date . Like wise in the year combo box.
> :
> : For example today is september 13 2006.
> :
> : So when he opens the page the combo boxes should display 13 September
> : 2006 .
> :
> : Now if he wants he can choose from the other dates months and years.
> : its done by giving SELECTED keyword in the option tag ,but in this case
> : selected date has to change daily.So do I need to write some script?
> :
> : Thanks
> : Divya
> :
>
> Here's a working example that also automatically adjusts the number of days
> in the day combo box if the year or month changes.
>
> <html>
> <head>
> <title>Select Date Test</title>
> <script type='text/vbscript'>
> Sub Window_Onload()
> Dim CurDate
> CurDate = Now
> CurDate = Array(Year(CurDate),Month(CurDate),Day(CurDate))
> AddOptions Form1.Year,CurDate(0) - 15,CurDate(0) + 15,CurDate(0)
> AddOptions Form1.Month,1,12,CurDate(1)
> AddOptions Form1.Day,1,31,CurDate(2)
> End Sub
>
> Sub AddOptions(Sel,Start,Finish,Index)
> Dim Count
> For Count = Start To Finish
> Sel.Add Window.Option(Count,Count)
> If Count = Index Then Sel.SelectedIndex = Sel.Length - 1
> Next
> End Sub
>
> Sub ChangeDay(YearValue,MonthValue)
> Dim Length
> Dim Count
> Dim Sel
> Set Sel = Form1.Day
> Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
> If Length = 0 Then Length = 31
> If Sel.Length > Length Then
> Sel.Length = Length
> ElseIf Sel.Length < Length Then
> For Count = Sel.Length + 1 To Length
> Sel.Add Window.Option(Count,Count)
> Next
> End If
> End Sub
> </script>
> </head>
>
> <body>
> <form name='form1'>
> <select name='year' onchange='changeDay me.value,me.form.month.value'>
> </select>
> <select name='month' onchange='changeDay me.form.year.value,me.value'>
> </select>
> <select name='day'></select>
> </form>
> </body>
> </html>


Re: How can a Combobox option the one which is the default selected change based on today's date? by Dr

Dr
Thu Sep 14 12:45:09 CDT 2006

JRS: In article <Ob7A7e11GHA.2176@TK2MSFTNGP04.phx.gbl>, dated Wed, 13
Sep 2006 13:12:05 remote, seen in news:microsoft.public.scripting.vbscri
pt, Walter Zackery <please_respond_to@group.com> posted :

> Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
> If Length = 0 Then Length = 31

Length = Day(DateSerial(YearValue, MonthValue+1, 0)

is simpler.

ISTM that "Length" will not work if tested in a Web page; Leng?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Re: How can a Combobox option the one which is the default selected change based on today's date? by Walter

Walter
Fri Sep 15 03:45:01 CDT 2006


"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
news:UwB5ACDlUZCFFwvX@merlyn.demon.co.uk...
: JRS: In article <Ob7A7e11GHA.2176@TK2MSFTNGP04.phx.gbl>, dated Wed, 13
: Sep 2006 13:12:05 remote, seen in news:microsoft.public.scripting.vbscri
: pt, Walter Zackery <please_respond_to@group.com> posted :
:
: > Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
: > If Length = 0 Then Length = 31
:
: Length = Day(DateSerial(YearValue, MonthValue+1, 0)
:
: is simpler.
:
: ISTM that "Length" will not work if tested in a Web page; Leng?
:
Length will work as fine as a variable name under IE. There is no global
property, method, reserved keyword in JScript, VBScript, or under the window
object named length. Perhaps you're thinking of window.length in Firefox and
other browsers? If so, it wouldn't matter because this script couldn't work
in those browsers anyway. Here's something that I'm surprised you
missed --). I should have adjusted the number of days in the Window_Onload
function to match the number of days in the current month. So if you're
still reading this thread divya, add the following line to the end of
Window_Onload:

ChangeDay Form1.Year.Value,Form1.Month.Value



Re: How can a Combobox option the one which is the default selected change based on today's date? by Dr

Dr
Fri Sep 15 16:26:56 CDT 2006

JRS: In article <el0d8MK2GHA.328@TK2MSFTNGP06.phx.gbl>, dated Fri, 15
Sep 2006 04:45:01 remote, seen in news:microsoft.public.scripting.vbscri
pt, Walter Zackery <please_respond_to@group.com> posted :
>"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
>news:UwB5ACDlUZCFFwvX@merlyn.demon.co.uk...
>: JRS: In article <Ob7A7e11GHA.2176@TK2MSFTNGP04.phx.gbl>, dated Wed, 13
>: Sep 2006 13:12:05 remote, seen in news:microsoft.public.scripting.vbscri
>: pt, Walter Zackery <please_respond_to@group.com> posted :
>:
>: > Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
>: > If Length = 0 Then Length = 31
>:
>: Length = Day(DateSerial(YearValue, MonthValue+1, 0)

Oops, another ) was needed.

>: is simpler.
>:
>: ISTM that "Length" will not work if tested in a Web page; Leng?
>:
>Length will work as fine as a variable name under IE.

For me, it did not. IE4, as per sig.

>There is no global
>property, method, reserved keyword in JScript, VBScript, or under the window
>object named length.

Length != length ' but difference is immaterial

> Perhaps you're thinking of window.length in Firefox and
>other browsers? If so, it wouldn't matter because this script couldn't work
>in those browsers anyway.

No, I know little of those.

It's a good idea to read the c.l.j FAQ.
--
© 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.

Re: How can a Combobox option the one which is the default selected change based on today's date? by Walter

Walter
Sat Sep 16 06:05:04 CDT 2006


"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
news:fJwreWEgqxCFFwsp@merlyn.demon.co.uk...
: JRS: In article <el0d8MK2GHA.328@TK2MSFTNGP06.phx.gbl>, dated Fri, 15
: Sep 2006 04:45:01 remote, seen in news:microsoft.public.scripting.vbscri
: pt, Walter Zackery <please_respond_to@group.com> posted :
: >"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
: >news:UwB5ACDlUZCFFwvX@merlyn.demon.co.uk...
: >: JRS: In article <Ob7A7e11GHA.2176@TK2MSFTNGP04.phx.gbl>, dated Wed, 13
: >: Sep 2006 13:12:05 remote, seen in
news:microsoft.public.scripting.vbscri
: >: pt, Walter Zackery <please_respond_to@group.com> posted :
: >:
: >: > Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
: >: > If Length = 0 Then Length = 31
: >:
: >: Length = Day(DateSerial(YearValue, MonthValue+1, 0)
:
: Oops, another ) was needed.
:
: >: is simpler.
: >:
: >: ISTM that "Length" will not work if tested in a Web page; Leng?
: >:
: >Length will work as fine as a variable name under IE.
:
: For me, it did not. IE4, as per sig.
:

You say it doesn't work, but you can't explain why it doesn't work.
Hmm......

: >There is no global
: >property, method, reserved keyword in JScript, VBScript, or under the
window
: >object named length.
:
: Length != length ' but difference is immaterial
:

If it's immaterial why mention it?

: > Perhaps you're thinking of window.length in Firefox and
: >other browsers? If so, it wouldn't matter because this script couldn't
work
: >in those browsers anyway.
:
: No, I know little of those.
:
: It's a good idea to read the c.l.j FAQ.

This is starting to get annoying. See ya'.



Re: How can a Combobox option the one which is the default selected change based on today's date? by Dr

Dr
Sat Sep 16 16:27:30 CDT 2006

JRS: In article <eDTH3$X2GHA.1292@TK2MSFTNGP03.phx.gbl>, dated Sat, 16
Sep 2006 07:05:04 remote, seen in news:microsoft.public.scripting.vbscri
pt, Walter Zackery <please_respond_to@group.com> posted :
>
>"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
>news:fJwreWEgqxCFFwsp@merlyn.demon.co.uk...
>: JRS: In article <el0d8MK2GHA.328@TK2MSFTNGP06.phx.gbl>, dated Fri, 15
>: Sep 2006 04:45:01 remote, seen in news:microsoft.public.scripting.vbscri
>: pt, Walter Zackery <please_respond_to@group.com> posted :
>: >"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
>: >news:UwB5ACDlUZCFFwvX@merlyn.demon.co.uk...
>: >: JRS: In article <Ob7A7e11GHA.2176@TK2MSFTNGP04.phx.gbl>, dated Wed, 13
>: >: Sep 2006 13:12:05 remote, seen in
>news:microsoft.public.scripting.vbscri
>: >: pt, Walter Zackery <please_respond_to@group.com> posted :
>: >:
>: >: > Length = 31 - Day(DateSerial(YearValue,MonthValue,31))
>: >: > If Length = 0 Then Length = 31
>: >:
>: >: Length = Day(DateSerial(YearValue, MonthValue+1, 0)
>:
>: Oops, another ) was needed.
>:
>: >: is simpler.
>: >:
>: >: ISTM that "Length" will not work if tested in a Web page; Leng?
>: >:
>: >Length will work as fine as a variable name under IE.
>:
>: For me, it did not. IE4, as per sig.
>:
>
>You say it doesn't work, but you can't explain why it doesn't work.
>Hmm......


I don't know in detail why. Using the following test HTML file,
I get a window saying

Internet Explorer Script Error
! An error has occurred in the script on this page.
Line: 2
Char: 1
Error: Object doesn't support this action: 'Length'
Code: 0
Do you want to ...

File : <script type="text/vbscript">
Length = 3
</script>

But if I remove a character from 'Length' then I get no error message.
Presumably 'Length' is an existing read-only Object. Its value appears
to be 0.

If one avoids using the sort of identifier spelling that might well be
already in use, one avoids such problems.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.