www.webdeveloper.com
Results 1 to 1 of 1

Thread: Disable form elements

  1. #1
    Join Date
    May 2004
    Posts
    167

    Question Disable form elements

    I have a form. One top of the form I have a checkbox. It is unchecked by default and the rest of the form fields are disabled. When Checkbox is checked the form fields become editable.

    I started writing function but it uses field names and becomes too long and bulky
    PHP Code:
    function disableForm() {
    if (
    document.myForm.myCheckbox.checked == true) {
       
    document.myForm.Field1.disabled false;
       
    document.myForm.Field2.disabled false;
       
    document.myForm.Field2.disabled false;
    } else {
       
    document.myForm.Field1.disabled true;
       
    document.myForm.Field2.disabled true;
       
    document.myForm.Field2.disabled true;
    }

    Isn't there a way I can add an ID to the fields that I wish to disable on load and then call that ID instead of writing two statements for each field?

    There are form fields that should not be affected by this checkbox too.
    Last edited by santa; 03-10-2009 at 02:05 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles