Loading ...
Sorry, an error occurred while loading the content.

Re: [JavaScript] Ok, I need help concerning a javascipt

Expand Messages
  • Jacob Wilson
    Hey Peter... I had a similar situation where I needed to generated all ridays of the year... Here is a sample of what I did... the Date object in javascript,
    Message 1 of 2 , Feb 6, 2004
    • 0 Attachment
      Hey Peter...

      I had a similar situation where I needed to generated all ridays of the year... Here is a sample of what I did... the Date object in javascript, when constructed without any arguments is initialized with today's date. that's exactly what 'today' variable is
      for. Now, Date object could also be initialized with milliseconds and it also
      support addition and substraction. there are 86400000 ms in a day. and
      we go back 14 days from today!

      the getDay() method on Date object returns 0 for Sunday, 1 for Monday
      and so on. so we get all days when getDay() == 1 or 2 or ...
      I hope it would gives you some clue...

      <javascript>
      function doIt() {

      var today = new Date();
      var fridays = new Array();
      for (i = 1; i <= 365; i++) {
      d = new Date(today - (86400000 * i));
      if (d.getDay() == 5) {
      fridays.splice(fridays.length, 0, d);
      }
      }

      for (i = 0; i < fridays.length; i++) {
      // show it in a text field on this page!
      document.forms[0].t1.value = document.forms[0].t1.value +
      fridays[i].toString();
      }
      }
      </javascript>


      Oh, and by the way, Array.splice() makes javascript Array object as
      dynamic and ArrayList in java!

      hope this would help.

      Thanks.
      -Jacob


      Peter Dickson <peter.dickson@...> wrote:
      Can someone who has a clue about javascript, explain to this idiot (me) where I am going wrong.

      What I am trying to achieve!! (laughing hysterically!!) is a 2 week cycle counting down to a specific date, where an ordering cycle is to be completed and I also need to display a date 1 week after the completed cycle date, to show a delivery date. This is where im stuffing up. Im having trouble adding 7 days to the end of cycle date. I have highlighted the area I believe is at fault.

      Im sure there alot of easier ways to do this, im just so inexperienced to know better.

      any constructive help would be appreciated

      Peter

      <script>
      //change the text below to reflect your own,
      var current="Today is last day to order for this order cycle!"
      var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
      function twoweeks(yr,m,d)
      {
      var today=new Date()
      var todayy=today.getYear()
      if (todayy < 1000)
      todayy+=1900
      var todaym=today.getMonth()
      var todayd=today.getDate()
      var todaystring=montharray[todaym]+" "+todayd+", "+todayy
      var futurestring=montharray[m-1]+" "+d+", "+yr
      var weekaheadstring=montharray[m-1]+" "+(todayd+(7*24*60*60*1000))+", "+yr
      var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
      if (difference==0)
      document.write(current)
      else if (difference>0)
      document.write("There are "+difference+" days before this order cycle finishes on the "+futurestring+" thank you. ")
      document.write("<br>")
      document.write("Delivery for this cycle will be sent on the "+weekaheadstring+" thank you.")
      }
      //enter the count down date using the format year/month/day
      twoweeks(2004,2,27)
      </script>






      [Non-text portions of this message have been removed]




      ---------------------------------
      Yahoo! Groups Links

      To visit your group on the web, go to:
      http://groups.yahoo.com/group/javascript_official/

      To unsubscribe from this group, send an email to:
      javascript_official-unsubscribe@yahoogroups.com

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



      ---------------------------------
      Do you Yahoo!?
      Yahoo! Finance: Get your refund fast by filing online

      [Non-text portions of this message have been removed]
    • Peter Dickson
      Can someone who has a clue about javascript, explain to this idiot (me) where I am going wrong. What I am trying to achieve!! (laughing hysterically!!) is a 2
      Message 2 of 2 , Feb 6, 2004
      • 0 Attachment
        Can someone who has a clue about javascript, explain to this idiot (me) where I am going wrong.

        What I am trying to achieve!! (laughing hysterically!!) is a 2 week cycle counting down to a specific date, where an ordering cycle is to be completed and I also need to display a date 1 week after the completed cycle date, to show a delivery date. This is where im stuffing up. Im having trouble adding 7 days to the end of cycle date. I have highlighted the area I believe is at fault.

        Im sure there alot of easier ways to do this, im just so inexperienced to know better.

        any constructive help would be appreciated

        Peter

        <script>
        //change the text below to reflect your own,
        var current="Today is last day to order for this order cycle!"
        var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
        function twoweeks(yr,m,d)
        {
        var today=new Date()
        var todayy=today.getYear()
        if (todayy < 1000)
        todayy+=1900
        var todaym=today.getMonth()
        var todayd=today.getDate()
        var todaystring=montharray[todaym]+" "+todayd+", "+todayy
        var futurestring=montharray[m-1]+" "+d+", "+yr
        var weekaheadstring=montharray[m-1]+" "+(todayd+(7*24*60*60*1000))+", "+yr
        var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
        if (difference==0)
        document.write(current)
        else if (difference>0)
        document.write("There are "+difference+" days before this order cycle finishes on the "+futurestring+" thank you. ")
        document.write("<br>")
        document.write("Delivery for this cycle will be sent on the "+weekaheadstring+" thank you.")
        }
        //enter the count down date using the format year/month/day
        twoweeks(2004,2,27)
        </script>






        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.