Currently, I have a text box and date-time local input that stores something into an array every time I click on a submit button. The arrays work, however, I do not seem to be able to put them into a table using a for loop and displaying them. Here is the JavaScript that is relevant:
var eventName = new Array();
var theDate = new Array();
var index = 0;
var index2 = 0;
function submitNewEvent() {
eventName[index] = document.getElementById("eventName").value;
index++;
theDate[index2] = document.getElementById("date").value;
index2++;
var newTable = "<table>";
for (var i=0; i < eventName.length; i++){
newTable += "" + eventName[i] + "<br>"
}
}
Here is how I am attempting to display the table in HTML:
<script>
document.write ('<p>colour1: ' + newTable + '</p>');
</script>
Any help and suggestions will be greatly appreciated!
java? please make sure to read this and this.submitNewEvent()? Where do you close your</table>? - Where are your<tr>elements? - Where are your<td>elements? - Do you know what are all the necessary elements to properly build a table? - What are all the elements you can use in a table?var eventName = [];is used for brevity. - Instead of the indexes variables you can simply useArray.push()likeeventName.push("blah")-document.writeis often referred as the JavaScript's bad parts (for often good reasons) and should be replaced with other methods.theDatearray?