473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

JS NOOB Alert - drop down date select box


I want a drop down date selection box on a form in the format of Mon 18
June 2007, that will go say 400 days in advance from the current date.

Can anyone point me in the right direction as I appear to be going in
ever decreasing circles . . .

TIA!

--
Buzby
There's nothing more dangerous than a resourceful idiot
Jun 18 '07 #1
4 2973
On Jun 18, 8:21 am, "Buzby" <g...@pumpupthe.netwrote:
I want a drop down date selection box on a form in the format of Mon 18
June 2007, that will go say 400 days in advance from the current date.

function generateSelect(){
var sel=document.createElement("select"),opt,dt;
var date=new Date();date.setDate(date.getDate()-1);
var days=['Sun','Mon','Tue','Wed','Thur','Fri','Sat']
var
months=['Jan','Feb','Mar','Apr','May','June','July','Aug', 'Sep','Oct','Nov','Dec']
for(var i=0;i<400;i++){
date.setDate(date.getDate()+1);
opt=document.createElement("option");
opt.text=days[date.getDay()]+" "+date.getDate()+"
"+months[date.getMonth()]+" "+date.getYear()
sel.add(opt)
}
document.body.appendChild(sel)
}

Jun 18 '07 #2
scripts.contact wrote:
On Jun 18, 8:21 am, "Buzby" <g...@pumpupthe.netwrote:
>I want a drop down date selection box on a form in the format of Mon 18
June 2007, that will go say 400 days in advance from the current date.


function generateSelect(){
var sel=document.createElement("select"),opt,dt;
var date=new Date();date.setDate(date.getDate()-1);
var days=['Sun','Mon','Tue','Wed','Thur','Fri','Sat']
var
months=['Jan','Feb','Mar','Apr','May','June','July','Aug', 'Sep','Oct','Nov','Dec']
for(var i=0;i<400;i++){
date.setDate(date.getDate()+1);
opt=document.createElement("option");
opt.text=days[date.getDay()]+" "+date.getDate()+"
"+months[date.getMonth()]+" "+date.getYear()
"+months[date.getMonth()]+" "+date.getFullYear()
sel.add(opt)
sel.appendChild(opt);
}
document.body.appendChild(sel)
}
;)

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 18 '07 #3
-Lost wibbled:
scripts.contact wrote:
On Jun 18, 8:21 am, "Buzby" <g...@pumpupthe.netwrote:
I want a drop down date selection box on a form in the format of
Mon 18 June 2007, that will go say 400 days in advance from the
current date.
>

function generateSelect(){
var sel=document.createElement("select"),opt,dt;
var date=new Date();date.setDate(date.getDate()-1);
var days=['Sun','Mon','Tue','Wed','Thur','Fri','Sat']
var
months=['Jan','Feb','Mar','Apr','May','June','July','Aug', 'Sep','Oct
','Nov','Dec'] for(var i=0;i<400;i++){
date.setDate(date.getDate()+1);
opt=document.createElement("option");
opt.text=days[date.getDay()]+" "+date.getDate()+"
"+months[date.getMonth()]+" "+date.getYear()

"+months[date.getMonth()]+" "+date.getFullYear()
sel.add(opt)

sel.appendChild(opt);
}
document.body.appendChild(sel)
}

;)
Thanks for the replies - still not quite there having tried both your
suggestions this one is nearly there (lines wrapped):-

function generateSelect(){
var sel=document.createElement("select"),opt,dt;
var date=new Date();date.setDate(date.getDate()-1);
var days=['Sun','Mon','Tue','Wed','Thur','Fri','Sat']
var
months=['Jan','Feb','Mar','Apr','May','June','July','Aug', 'Sep','Oct','N
ov','Dec']
for(var i=0;i<400;i++){
date.setDate(date.getDate()+1);
opt=document.createElement("option");
opt.text=days[date.getDay()]+" "+date.getDate()+"
"+months[date.getMonth()]+" "+date.getFullYear()
sel.add(opt)
}
document.body.appendChild(sel)
}
When I call the function it displays the drop down menu perfectly but
has an error message next to it saying 'undefined'. If I change the
sel.add(opt) line to sel.appendChild(opt); I get an empty box with
undefined also.

I just don't get which bit is undefined!

Thanks - much appreciated!
--
Buzby
There's nothing more dangerous than a resourceful idiot
Jun 19 '07 #4
On Jun 19, 8:14 pm, "Buzby" <g...@pumpupthe.netwrote:
[...]
Thanks for the replies - still not quite there having tried both your
suggestions this one is nearly there (lines wrapped):-
I can't say I agree with a select with 400 options, but anyhow...

function generateSelect(){
var sel=document.createElement("select"),opt,dt;
var date=new Date();date.setDate(date.getDate()-1);
var days=['Sun','Mon','Tue','Wed','Thur','Fri','Sat']
var
months=['Jan','Feb','Mar','Apr','May','June','July','Aug', 'Sep','Oct','N
ov','Dec']
for(var i=0;i<400;i++){
date.setDate(date.getDate()+1);
Replace from here...
opt=document.createElement("option");
opt.text=days[date.getDay()]+" "+date.getDate()+"
"+months[date.getMonth()]+" "+date.getFullYear()
sel.add(opt)
to here with:

sel.options[i] = new Option( days[date.getDay()]
+ " " + date.getDate() + " "
+ months[date.getMonth()] + " "
+ date.getFullYear();
}
document.body.appendChild(sel)

}
Alternatively, you can use createElement and append the option text by
creating a text node and appending that rather than setting the text
attribute, but I think new Option is simpler.
--
Rob

Jun 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
4
by: Coleen | last post by:
Please see threads on "Dumb question about Message boxes" - I went to the specified link - this works great if all you want to do is display a message box before any of your script behind the...
2
by: ramesh | last post by:
hi, I am using Com+ in my application. It will have InsertRecords,selectRecords,updateRecords function. In the Web Form i have Drop-down list. I want to select records from SQL and add it to this...
3
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the...
3
by: Hanoodah | last post by:
Good morning all, Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about...
3
by: phpmagesh | last post by:
Hi, I have a drop down in my page, what i will do with that drop down is i have a table in my database, which have values and this table will refer that ID and pick the name of that values and...
2
by: phpnewbie26 | last post by:
I currently have two drop down menus where the second one is populated from the first one. My second drop down menu should be able to do multiple selection. I have searched online and found out how...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.