Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2006, 11:05 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default Date Manipulation

Hi,

I have to create a drop down box in javascript (select - options) but the date range will be dictated by an xml document.

<Products>
<Product ID="p6" firsIns="2004-01-01" lastIns="2004-12-31" />
<Product prodID="p5 firsIns="2003-01-01" lastIns="2005-12-31" />
</Products>

So in this case the earlist date is - firsIns="2003-01-01"
and the last date is - lastIns="2005-12-31".

Basically, I have to loop through the xml and find the earliest insertion and last insertion and then populate the drop down list based on the firt and last date.

The select should look something like this:

<select id="selDummyDate1">
<option value="2003.1">Jan 03</option>
<option value="2003.2>feb 03</option>
<option value="2003.3>Mar 03</option>
---------
<option value="2004.1>Jan 04</option>

----------
<option value="2005.12>Dec 05</option>
</select>

I cannot figure out how to populate the select tag with the date range starting from Jan 03 up to Dec 05 (including all months in 2003, 2004 and 2005).

Please note that what dictate the month is the number "01" after the year (2003-01-01) and I will have to change 01 to Jan and so on. I will also have to add the value like value="2003.1" (year.month)

I would appreciate very much if someone could help with the code. Is it possible to do it with JavaScript ??

Cheers

CP


 
Old May 4th, 2006, 04:37 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

I am sorry if my explanation was not clear. To simplify it this is what I would like help with.

If have two dates like these:

Initial date
2003-01-01

Last date
2005-12-31

How do I create a drop down list with all the month names and years in that range? And the value of the options should have this format for Jan 2003 and so on:

<options value="2003.1">

This is what the drop down should look like:

<select id="selDummyDate1">
  <option value="2003.1">Jan 03</option>
  <option value="2003.2>feb 03</option>
  <option value="2003.3>Mar 03</option>
  --------- and so on
  <option value="2004.1>Jan 04</option>
  ---------- and so on up to Dec 2005
  <option value="2005.12>Dec 05</option>
</select>

I do not know how to calculate the date range and would really appreciate some help.

Cheers,

CP



 
Old May 5th, 2006, 02:15 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

This is what I have tried to do so far but it is not what I need and I cannot figure out how to do that. I need to start from a predefined date like 2003-01-01
and an end date like 2005-12-31.

Then I need to create a loop that will get all the months and year in the range and create the option for the select tag.

Please could someone help ?

Cheers



<html>
  <head>

    <script type="text/javascript">
        var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
                                "Out", "Nov", "Dec")

        var now = new Date()
        var yy=now.getYear();


        function init()
        {

        var sel = document.getElementById("selDate")
        var theList = sel.options

        for(i=0;i<months.length;i++)
        {
            var n = i+1
            var option = new Option(months[i]+" "+yy , yy+"."+n)
            theList[i] = option

        }
        alert(theList.innerHTML)
        }

    </script>

  </head>
  <body onload="init()">

    <form id="Form1" method="post">
    <select id="selDate">

    </select>


     </form>

  </body>
</html>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Need advice to clean up my date manipulation code jasoncompo Beginning VB 6 1 June 2nd, 2006 01:29 PM
HELP Needed in Date Manipulation kunjan SQL Language 9 March 19th, 2006 09:51 PM
Date manipulation otarboy Access 1 September 20th, 2004 11:50 AM
DataGrid manipulation burdickdave ASP.NET 1.x and 2.0 Application Design 1 July 8th, 2003 01:11 PM
String Manipulation Ben Access VBA 2 July 8th, 2003 05:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.