Advertisement

04.25.2008 at 06:29AM PDT, ID: 23353387
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

List days between 2 dates - output listed in textarea

Asked by carelfg in JavaScript

Tags: ,

Hi - I wanted a solution with Javascript that can list the days between 2 dates after the user has entered these 2 values.
The values entered must be within a form and the output list also in a form field.
HonorGod helped me to adjust my script and the result was the attached code.
However, the dates in the textarea aren't displayed each on a seperate line.
I want those dates to be listed below each other, each on it's own line.
I have been trying different variations with /n or /n/r and even <br>  but no luck.

Any help is appreciated - and if this sounds like a very simple task - I'm a newbie with Javascript.

Thanks
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> between </title>
<script type='text/javascript'>
  //----------------------------------------------------------------------------
  // Name: field()
  // Role: Locate the document with the specified id
  //----------------------------------------------------------------------------
  function field( id ) {
    var ele = document.getElementById( id );
    if ( !ele ) {
      alert( 'Specified document element not found.  id="' + id + '"' );
    }
    return ele;
  }
 
  //----------------------------------------------------------------------------
  // Name: padout()
  // Role: prepend a leading '0' to values < 10 (e.g., 0..9)
  //----------------------------------------------------------------------------
  function padout( number ) {
    return ( number < 10 ) ? '0' + number : number;
  }
 
  //----------------------------------------------------------------------------
  // Name: showDates()
  // Role: Generate all the dates in the specified range
  //----------------------------------------------------------------------------
  function showDates( startDate, endDate ) {
    var result = '';
    while ( startDate < endDate ) {
      result += '\n' + startDate.getFullYear() + '-' + padout( startDate.getMonth() + 1 ) + '-' + padout( startDate.getDate() );
      // add a day to the date:
      startDate.setDate( startDate.getDate() + 1 );
    }
    return result.substring( 1 );
  }
 
  //----------------------------------------------------------------------------
  // Name: checkDates()
  // Role: Verify user input & generate requested dates for valid values.
  //----------------------------------------------------------------------------
  function checkDates( startId, stopId, outputId ) {
    var start     = field( startId );
    var stop      = field( stopId );
    var output    = field( outputId );
    var dateRE    = /^(\d{2,4})-(\d{1,2})-(\d{1,2})$/;
    var startDate = null;
    var stopDate  = null;
    if ( start && start.value.match( dateRE ) ) {
      var startDate = new Date( RegExp.$1, RegExp.$2 - 1, RegExp.$3 );
    }
    if ( stop && stop.value.match( dateRE ) ) {
      var stopDate = new Date( RegExp.$1, RegExp.$2 - 1, RegExp.$3 );
    }
    if ( output ) {
      output.innerHTML = showDates( startDate, stopDate );
    }
  }
</script>
</head>
<body>
  <table border='1'>
    <tr>
      <td>Start date:</td>
      <td><input type='text' size='10' id='start' onchange='checkDates("start","stop","results")' value='YYYY-MM-DD'></td>
    </tr>
    <tr>
      <td>End date:</td>
      <td><input type='text' size='10' id='stop'  onchange='checkDates("start","stop","results")' value='YYYY-MM-DD'></td>
    </tr>
  </table>
  <textarea id='results'></textarea>
</body>
</html>
Related Solutions: LIst days between 2 dates
[+][-]04.25.2008 at 07:52AM PDT, ID: 21440114

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 07:59AM PDT, ID: 21440192

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 08:24AM PDT, ID: 21440479

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 08:26AM PDT, ID: 21440503

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 08:26AM PDT, ID: 21440515

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 01:30AM PDT, ID: 21444909

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 01:43AM PDT, ID: 21444929

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 10:44AM PDT, ID: 21446247

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 11:15AM PDT, ID: 21446351

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 11:49AM PDT, ID: 21446504

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: Javascript, IE;Firefox
Sign Up Now!
Solution Provided By: HonorGod
Participating Experts: 2
Solution Grade: B
 
 
[+][-]06.19.2008 at 10:14AM PDT, ID: 21824245

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_Related_20080208