# Disabling Form Parts

**URL:** <https://forum.kirupa.com/t/disabling-form-parts/176335>\
**Category:** web dev\
**Created:** [January 23, 2006, 12:12am UTC](https://forum.kirupa.com/t/disabling-form-parts/176335 "2006-01-23T00:12:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamerp](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@dreamerp](https://forum.kirupa.com/u/dreamerp)\
**Post date:** [January 23, 2006, 12:12am UTC](https://forum.kirupa.com/t/disabling-form-parts/176335/1 "2006-01-23T00:12:04Z")

</div>

Hello,

I don’t do much Javascript work and I was hoping someone could help me debug the following code.

I am looking to disable a form part (a file upload field) if they do not check off a checkbox.

File Field Name: userfile  
Checkbox Name: editimage

Here is the javascript

```auto

 <script>
      function disablefield()
{
  // check everything you need to check and then
  if (document.forms[0].editimage.value == "yes"){
      document.forms[0].userfile.disabled = false;
} else if (document.forms[0].editimage.value == "") {
document.forms[0].userfile.disabled = true;
}}
      
      </script>

```

Here is parts of the HTML form. The checkbox and the file field-

```auto

<input onChange="disablefield(this);" name='editimage' type='checkbox' id='editimage' value='yes'>

<input disabled='disabled' name='textfield' type='text' value='http://www.' size='13'>

```

The javascript is placed in between the two.

Please help!

Thanks,

peter
