I'm trying to create a dynamic form using JS and PHP, I've done the PHP part, where the user selects how many rows he wants and the program generate that number of rows. The JS part is to display a HTML select box only if a checkbox is checked. I done that using the following function:
var checkBox = document.getElementById("box");
function repeatedCheck(){
if(checkBox.checked==true){
document.getElementById('sel').innerHTML="<select name='sel'>
<option value='1'>1</option>
<option value='2'>2</option>
.
.
//more options ..
</select>";}
else{
document.getElementById('sel').innerHTML="";
}
}
and this is the HTML part which generated by PHP program:
<table>
<?php
for($i=1;$i<=$numOfRows;$i++){
echo "<tr>";
echo "<td><input type='checkbox' id='box' name='repeated' onclick='repeatedCheck()'></td>";
echo "<td id='sel'></td>";
echo "</tr>";
}
?>
</table>
The problem is, nothing shows up when the checkbox is checked.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…