Search code examples
javascriptdojox.charting

Appending Javascript Array Values to the DOJO div


I have a Array of Values as shown above .

myarray2.push("10-FEB-11");
myarray2.push("11-FEB-11");
myarray2.push("12-FEB-11");
myarray2.push("13-FEB-11");
myarray2.push("14-FEB-11");

I want to have these Values inside the div hrXAxisSlider as shown (Currently its hardcoded , but is that possible )

  <div id="hrXAxisSlider"
  dojoType="dojox.form.HorizontalRangeSlider">


   <ol dojoType="dijit.form.HorizontalRuleLabels" >
     <li>10-FEB-11</li><li>11-FEB-11</li><li>12-FEB-11</li><li>13-FEB-11</li><li>14-FEB-11</li>
   </ol>


</div>

Solution

  • You can accomplish this with a simple javascript for loop:

    var ol = document.getElementById('hrXAxisSlider')
                     .getElementsByTagName('ol')[0],
        ma2l = myarray2.length,
        i, 
        htmlFrag = '';
    
    for (i = 0; i < ma2l; i++) {
        htmlFrag += '<li>' + myarray2[i] + '</li>';
    }
    
    ol.innerHTML = htmlFrag;
    

    See example →