Convert to VBScript to JavaScript ?

Discussion in 'Javascript' started by davidgordon@scene-double.co.uk, Oct 17, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. Zif Guest

    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
     
    Zif, Oct 17, 2005
    #2
    1. Advertising

  3. 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 <> 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.
     
    Dr John Stockton, Oct 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jamie
    Replies:
    1
    Views:
    729
    Jamie
    Dec 5, 2003
  2. Replies:
    1
    Views:
    634
  3. David

    Convert from VBScript...

    David, Aug 2, 2004, in forum: Javascript
    Replies:
    6
    Views:
    185
    Dr John Stockton
    Aug 3, 2004
  4. Boris Skoblo

    convert Vbscript to Perl code

    Boris Skoblo, Jan 15, 2007, in forum: Perl Misc
    Replies:
    28
    Views:
    430
    Mark Donovan
    Jan 19, 2007
  5. balzer

    convert VBScript into Javascript

    balzer, May 13, 2010, in forum: Javascript
    Replies:
    5
    Views:
    1,007
    Evertjan.
    May 13, 2010
Loading...

Share This Page