I need the following functionality :
"When a checkbox is checked, the corresponding textbox must be highlighted and user could be able to enter some text into that.."
Checkboxes are working, but when a checkbox is checked, the corresponding textbox is not activating, how to solve this?
Here is my php code :
<?php
if ($handle = opendir('/year_no/albums')) {
$blacklist = array('.', '..');
while (false !== ($file = readdir($handle))) {
if (!in_array($file, $blacklist)) {
echo "<form name='form1'>
<div class='controlset-pad'>
<font color='black'><label><input type='checkbox' name='album[]' value='$album' onclick='enable_text(this.checked)' class='medium'/><span>$album</span></label><br/></div>";
echo"<script>
function enable_text(status)
{
status=!status;
document.form1.other_name.disabled = status;
}
</script>";
echo "<div class='field4'><label>Add your comment here</label><input type='text' name='other_name' class='medium' disabled='disabled'/></div></form>";
}
}
closedir($handle);
}
?>
MODIFIED CODE:
<script>
function enable_text(status, sub)
{
status=!status;
document.getElementById(sub).disabled = status;
}
</script>
<form name='form1'>
<?php
if ($handle = opendir('/year_no/albums')) {
$blacklist = array('.', '..');
while (false !== ($file = readdir($handle))) {
if (!in_array($file, $blacklist)) {
echo "<div class='controlset-pad'>
<font color='black'><label><input type='checkbox' name='file[]' value='$file' onclick='enable_text(this.checked, $file)' class='medium'/><span>$file</span></label>
</div>";
echo "<div class='field4'><label>Add your comment here</label><input type='text' name='sub' id='$file' class='medium' disabled='disabled'/></div>";
}
}
closedir($handle);
}
?>
</form>
font
tag is long deprecated. Use CSS instead. – Waleed Khan Dec 25 '12 at 7:19$album
, with a function likehtmlentities
to prevent accidental (or malicious) XSS. – Waleed Khan Dec 25 '12 at 7:21