Reputation: 43
script language="javascript" type="text/javascript">
function moveNumbers(num) {
if(document.getElementById("selector").checked){
var txt=document.getElementById("result").value;
txt=txt + num;
document.getElementById("result").value=txt;
}
else{
document.getElementById("result").value=txt="";
}
}
</script>
<textarea id="result" name="image_id" rows="8" cols="11" readonly>
</textarea>
<tr>
<?php
$path = "photos/";
$dir_handle = @opendir($path) or die("Unable to open folder");
echo "<table height='500px'width='800px'align='center'border='1'>";
echo "<tr>";
while (false !== ($file = readdir($dir_handle))) {
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
{
echo ($x % 6 == 0) ? "</tr><tr>" : "";
echo "<td><input type='checkbox' id='selector' value='$file' onclick='moveNumbers(this.value)'>
<img src='photos/$file'alt='$file' style='height:auto;width:50%;'alt='$file'>
<br>
$file
</td>";
$x++;
}
}
echo "</tr>";
echo "</table>";
closedir($dir_handle);
?>
Hi all, having a little trouble with the check boxes. PHP part lists image files with check boxes next to them. The problem I'm having is that only the first image in the list with the check box will add text input to the text area. Once the first check box is selected the other check boxes work? Any ideas? Cheers.
Upvotes: 0
Views: 77
Reputation: 91734
You are using this in your javascript:
if(document.getElementById("selector").checked){
And all your checkboxes have the same ID #selector
so your javascript will use the first one it finds. Note that you can not have duplicate ID's in your html.
Upvotes: 2