By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,819 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,819 IT Pros & Developers. It's quick & easy.

Convert to VBScript to JavaScript ?

P: n/a

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

Oct 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Zif
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
Oct 17 '05 #2

P: n/a
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, Zif <Zi***@hotmail.com> posted :

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 :-(.

--
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.
Oct 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.