title: how to call my javascript function from within this specific context
body: <p>can anyone please tell me how to call the function GetDuration from within the following context:</p>
  
  <pre><code>@{
  ...
  ...
  &lt;div&gt;  GetDuration(@item.StartDate, @item.EndDate) &lt;/div&gt;
  ...
  ...
  }
  </code></pre>
  
  <p>The function <code>GetDuration()</code> dynamically creates another DIV inside the parent DIV mentioned in my context.</p>
  
  <p>I have 2 problems:</p>
  
  <ul>
  <li>I do not know how to call my function <code>GetDuration()</code> from the spot shown in the code</li>
  <li><code>startdatum.Month.ToString("MMMM");</code> returns <code>"MMMM"</code> instead of the name of the month</li>
  </ul>
  
  <p>Thanks in advance!</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function GetDuration(startdatum, einddatum) {
      var maand1 = startdatum.Month.ToString("MMMM");
      var maand2 = einddatum.Month.ToString("MMMM");
      var duration = "Date: ";
      if (maand1 == maand2) {
          duration += item.Startdate.Day.ToString()
              + " - " + item.Enddate.Day.ToString()
              + " " + maand1
              + " " + item.Startdate.Year.ToString();
      }
      else {
          duration += item.Startdate.Day.ToString()
              + item.Startdate.Month.ToString("MMMM")
              + " - " + item.Enddate.Day.ToString()
              + " " + item.Enddate.Month.ToString("MMMM")
              + " " + item.Startdate.Year.ToString();
      }
      var dynDiv = document.createElement("div");
      dynDiv.class = "HP_DateDiv";
      dynDiv.innerHTML = duration;
      document.body.appendChild(dynDiv);
  }
  
  &lt;/script&gt;
  
  
      @{  string prevYear = "";
  
      foreach (var item in ViewData.Model) {
  
          string year = item.StartDate.Year.ToString();
          if (year != prevYear)
          {
              &lt;div class="contentheader"&gt; 
                  @year Formula 1 Tickets
              &lt;/div&gt;
  
              prevYear = year;  
          }
          &lt;div class="HP_eventBodyDiv"&gt;
              &lt;div class="HP_picDiv" style = "width:100px; height:100px;"&gt;
                  &lt;a href="http://www.cssdrive.com/" class="highlightit"&gt;&lt;img  src="../../Content/Pics/auto.jpg" alt="oto" height="50" width="50"/&gt;&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="HP_eventDiv"&gt;
                  &lt;div class="HP_eventNameDiv"&gt;@item.Name
              &lt;/div&gt;
  &lt;!--This is the spot to call my function with something like "GetDuration(@item.StartDate, @item.EndDate)"--&gt;
                  &lt;div class="HP_viewBuyBtnsDiv"&gt;
                      &lt;input id="btn_View" type="button" value="View Event" class="contentbtn"/&gt;
                      &lt;input id="btn_Buy" type="button" value="Buy Tickets" class="contentbtn"/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;            
  
          };
       }
  </code></pre>