473,412 Members | 2,599 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,412 software developers and data experts.

Convert to VBScript to JavaScript ?


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
2 8852
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
29
by: Christopher Brandsdal | last post by:
If I have a .ASP page that runs JScript code - is it possible to include an ..ASP page that runs VBscript???
5
by: Bill | last post by:
I need to convert a variable, nNum, into a two-character string. nNum is always less than 100. If nNum is 0, the string needs to be "00", if it's 1, it needs to be "01", if it's 34, it needs to...
1
by: darcykahle | last post by:
Is there any way of converting an existing access form into html format? The form in question has built-in visual-basic code, which gets commented out when you use the "save as" method, instead of...
10
by: thinktwice | last post by:
in my script file , i need call a method of a atl com module(implemented in vc++), which returan an safearray. i don't know how to convert it into array in jscript. i have tried serveral ways to...
3
by: rishabhshrivastava | last post by:
Hello All, How can I convert a value to Double in JavaScript??? In vbscript i believe its done as cDbl(Value) I tried lots of way but getting a value of "NaN". Any suggestions/ideas will...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: sathyan8294 | last post by:
what is websites for convert javascript to vbscript?
2
by: murugavelmsc | last post by:
Hi, i have a javascript code. I want to convert into VBscript. pls help me Javascript Code:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.