Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 4th, 2006, 11:05 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
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


Reply With Quote
  #2 (permalink)  
Old May 4th, 2006, 04:37 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
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



Reply With Quote
  #3 (permalink)  
Old May 5th, 2006, 02:15 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
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>


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.