On the right of each field I have a checkbox, if the user checks the checkbox, the field on the left must become editable, if the user unchecks the checkbox, the field must come back to be redonly and disabled.
I'm trying to do that with this code
<script type="text/javascript">
function toggleVariazione(field)
{
var campo = field.value.toString();
if(document.registralibro.campo.disabled == true)
{
document.registralibro.campo.disabled = false;
document.registralibro.campo.readOnly = false;
}
else
{
document.registralibro.campo.disabled = true;
document.registralibro.campo.readOnly = true;
}
}
</script>
//one of the fields
<textarea name='biografia' cols='40' rows='5' readonly disabled></textarea>
<input type='checkbox' name='variazioni[]' onclick='toggleVariazione(this)' value='biografia' />
//other fields below...
What should happen is:- user checks the checkbox
- toggleVariazione() is called
- variable "campo" contains the value of the checkbox, which is the same as the field name to be switched
- the variable "campo" is used to get the field to be set editable or disabled
This doesn't work, I suppose because I can't use the variable "campo" to get the field object.
Is that the problem?
Is there a to do what I need?
I don't want to write a different function for each field.


Sign In
Create Account


Back to top









