This is a project for uni for PHP/JavaScript. The concept is that we create an empty table, then get an input from the user and put this text in the odd lines of the table. Thing is, I've created the table and I can't get to pass the text to multiple paragraphs located inside the cells of the odd lines. I tried with getElementById to fill the cell's paragraph but I found out that each paragraph needs a unique id and so it fills only the first cell. Then I tried getElementsByClassName but this doesn't work cause there's no .innerHTML for it. Basically, all I want to do is take the same input and distribute it to multiple paragraphs or directly to the cells if there's a way. Code is at the bottom. The script doesn't work right now, I just left it in.
Thank you
<body>
<p class="p1">5th excercise Php</p><br><br><br>
<input type="button" id="btn" value="Give Input"><br><br>
<?php
echo "<table>";
for($i=1;$i<=10;$i++){
echo "<tr>";
for($j=1;$j<=10;$j++){
if($i % 2 == 0){
echo "<td style='background-color:green;color:green;'>"."<p>"."."."</p>"."</td>";
}
else{
echo "<td style='background-color:red; color:red;'>"."<p>"."."."</p>"."</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>
<script>
document.getElementById("btn").onclick= function(){f()}
function f(){
var x= prompt("Give input");
document.getElementById("").style.color = "black";
document.getElementById("").innerHTML= x;
}
</script>
</body>