Hi,
This is a javacript problem, but it is specific to PHP, since PHP wants you have have [] after the name in the file upload field.
It seems that javascript doesn't like the array brackets, so instead of being able to reference the field from within Javascript, I pass the object ('this') into the function from the event call. I think I could get around my problem using setInterval if I could reference the file field from the javascript, but I can't.
Here's the details:
I have a checkbox that is a "Remove Image?" checkbox. Now, the goal is to have this unchecked and disabled if the file field has been selected (which is named "userfile[]").
I've got part of it working. If the user selects a file, the checbox does indeed uncheck and become disabled. I'm also trying to add functionality so that if the user decides (after selecting a file) that they don't want to change the Image but remove it instead. The problem is that after clearing the contents of the file field, the checkbox remains disabled. I tried calling the same javascript function (see below) using onBlur() but it doesn't seem to have any affect. Below is the javascript and the event handler calls:
<script>
<!--
function fileFieldExcludesCheckbox(obj){
if(obj.value==""){
document.form1.RemoveImage.disabled=false;
return;
}else{
document.form1.RemoveImage.checked=false;
document.form1.RemoveImage.disabled=true;
}
}
//-->
</script>
<input type="file" name="userfile[]" size="40" value="" onfocus="javascript:fileFieldExcludesCheckbox(this)";
onSelect="javascript:fileFieldExcludesCheckbox(this)";
onChange="javascript:fileFieldExcludesCheckbox(this)";
onBlur="javascript:fileFieldExcludesCheckbox(this)";
onClick="javascript:fileFieldExcludesCheckbox(this)";
I don't think onClick is an event handler for this but I included it to show that it also has no effect. The only problem is that when a user clears the file field, the checkbox remains disabled.
Thanks in advance for any thoughts.