Reputation: 19
I have created the arrays and have made it to view when submit button is clicked. The coming below is the program code that I have written. But the thing is when the html file arrayusingforloop1.html is opened, there is a small square table is shown even before clicking the Submit button.But I want to show only the submit button not that small table. Then, when Submit button is clicked the arrays with the table to be shown. So Please give me solution for that.
Code for arrayusingforloop1.html:
<script>
function array() {
var table1 = "<table id='tabl123' ><thead></thead>";
table1 += "<tr><label id='lb1'></label></tr><BR><tr><label id='lb2'></label></tr><BR><tr><label id='lb3'></label></tr><br><tr><label id='lb4'></label></tr><br><tr><label id='lb5'></label></tr><br><tr><label id='lb6'></label></tr><br><tr><label id='lb7'></label></tr><br><tr><label id='lb8'></label></tr><br><tr><label id='lb9'></label></tr><br><tr><label id='lb10'></label></tr></table>";
var tablabc = document.getElementById("dynamic");
tablabc.innerHTML = table1;
arr = [" Lee  ", "22", "cse"];
text = "";
var i;
for (i = 0; i < arr.length; i++) {
text += " " + arr[i] + " ";
}
document.getElementById("lb1").innerHTML = text;
arr1 = [" ram  ", "22", "cse"];
text1 = "";
var a;
for (a = 0; a < arr1.length; a++) {
text1 += " " + arr1[a] + " ";
}
document.getElementById("lb2").innerHTML = text1;
arr2 = [" mei  ", "22", "cse"];
text2 = "";
var c;
for (c = 0; c < arr2.length; c++) {
text2 += " " + arr2[c] + " ";
}
document.getElementById("lb3").innerHTML = text2;
arr3 = [" Jas  ", "22", "cse"];
text3 = "";
var d;
for (d = 0; d < arr3.length; d++) {
text3 += " " + arr3[d] + " ";
}
document.getElementById("lb4").innerHTML = text3;
arr4 = [" Dpu  ", "22", "cse"];
text4 = "";
var e;
for (e = 0; e < arr4.length; e++) {
text4 += " " + arr4[e] + " ";
}
document.getElementById("lb5").innerHTML = text4;
arr5 = [" Bav  ", "21", "cse"];
text5 = "";
var f;
for (f = 0; f < arr5.length; f++) {
text5 += " " + arr5[f] + " ";
}
document.getElementById("lb6").innerHTML = text5;
arr6 = [" jai  ", "22", "cse"];
text6 = "";
var g;
for (g = 0; g < arr6.length; g++) {
text6 += " " + arr6[g] + " ";
}
document.getElementById("lb7").innerHTML = text6;
arr7 = [" Vic  ", "22", "cse"];
text7 = "";
var h;
for (h = 0; h < arr5.length; h++) {
text7 += " " + arr7[h] + " ";
}
document.getElementById("lb8").innerHTML = text7;
arr8 = [" lav  ", "22", "cse"];
text8 = "";
var j;
for (j = 0; j < arr8.length; j++) {
text8 += " " + arr8[j] + " ";
}
document.getElementById("lb9").innerHTML = text8;
arr9 = [" Sid  ", "22", "cse"];
text9 = "";
var k;
for (k = 0; k < arr5.length; k++) {
text9 += " " + arr9[k] + " ";
}
document.getElementById("lb10").innerHTML = text9;
}
</script>
</head>
<body>
<style>
#dynamic {
padding: 15px;
height: 50px;
width: "100%";
border-style: solid;
border-width: 5px;
background-color: yellow;
color: red;
}
tr {
border: 1px solid black;
border-style: solid;
border-width: 5px;
}
#tabl123 {
padding: 15px;
height: 50px;
width: "100%";
border: 1px solid black;
border-style: solid;
border-width: 5px;
color: red;
}
</style>
<table id="dynamic" border="1" />
<button onclick="array()">submit</button>
Please give me solution for this.
Upvotes: 0
Views: 111