da*********@scene-double.co.uk wrote:
Hi,
I have some pages with this VBScript code, which obviously does not
work in Firefox. How can I convert this to Javascript in order for my
web page to work in Firefox ? It basically fills a drop down with a
list of dates that a user can select.
Appreciate any help you can offer
----------------------
<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbFriday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Date.Options
For Count = 1 To 40
StrDate = "Friday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate),2) & "/" & Year(TheDate)
Options.Add Window.Option(StrDate,"for " & StrDate)
TheDate = TheDate + 7
Next
End Sub
</script>
The usual deal is to firstly describe what you want in plain language,
you know, 'requirements'. By stating your requirements in VBscript,
you immediately discount those who don't know it or don't care for it.
I'll guess that you want to generate a set of options with dates
starting from the next Friday for 40 weeks.
That stuff is much better done on the server, you have no idea what
the date/time of a users' system is, whether it is accurate or whether
it bears a suitable correlation to your location or that of your
server. You also avoid any issues with script incompatibility or
non-availability.
For the record, here's a script that does the above based on the date
of the user's system. But I wouldn't use it for anything important.
<form action="" name="formA">
<select name="weekDate" style="font-family: courier, sans-serif;">
<option>Select a date</option>
</select>
</form>
<script type="text/javascript">
function addDates(sel)
{
var months = ['Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'];
var numDates = 40; // number of dates to calculate
var daysBetween = 7; // days to add each time
var now = new Date(); // start from today
// Use following to set the date for testing
// var now = new Date(2005, 9, 21);
// Set the date to the next Friday
now.setDate(now.getDate() - ((now.getDay()+2)%7));
var i=1;
var optValue, optText;
while ( i <= numDates ){
now.setDate(now.getDate() + daysBetween);
optValue = now.getFullYear()
+ '-' + addZ(now.getMonth()+1)
+ '-' + addZ(now.getDate());
optText = now.getFullYear()
+ '-' + months[now.getMonth()]
+ '-' + addZ(now.getDate());
sel.options[i++] = new Option(optText, optValue);
}
}
function addZ(x)
{
return (x<10)? '0'+x : x;
}
window.onload = function () {
addDates(document.forms['formA'].elements['weekDate']);
};
</script>
--
Zif