Quote:
Originally Posted by sanidhya09
function Noida()
{
var a=new Array;
a[0]="sector1";
a[1]="sector2";
a[2]="sector3";
var i;
for(i=0;i<=((a.length)-1);i++){
document.getElementById("demo").innerHTML=a[i];
//document.write(a[i]);
}
}
I want to print all the array value in the "same" document
in <p id="demo"></p>
|
This doesn't work because you're just swapping out the innerHTML each time.
I figured you'd want some spaces between your concatenations. Obviously you can just take out the space if you don't want/need it.
EDIT: I just realized. devnull's and my posts do pretty much the exact same thing. Probably the reason it's not working (if that's the entirety of your HTML up there) is because you don't have a "<p id="demo"></p>" in the first place.
Code:
function Noida()
{
var a=new Array;
var result="";
a[0]="sector1";
a[1]="sector2";
a[2]="sector3";
var i;
for(i=0;i<=((a.length)-1);i++)
result=result + a[i] + " ";
document.getElementById("demo").innerHTML=result;
}