Convert to VBScript to JavaScript ?

D

davidgordon

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>

-----------------------

Thanks


David
 
Z

Zif

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>
 
D

Dr John Stockton

JRS: In article <435391c8$0$28207$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Mon, 17 Oct 2005 21:58:19, seen in
news:comp.lang.javascript said:
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));

ISTM add 7 for next Friday.
I think the OP's code allowed today as a starting point, in which case
add 6 and adjust the getDay()+ number by 1.

The OP allowed his posting agent to wrap his code :-(.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top