Enabling disabled option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KeredDrahcir
    Contributor
    • Nov 2009
    • 426

    #1

    Enabling disabled option

    Can somebody help me. I'm trying to set a disabled option to enabled when the user click on a link. I've tried just about everything and I'm practically pulling my hair out.

    The option I want to enable is a test box.
    Code:
    <input type="text" name="input_name<?=$i;?>" id="input_id<?=$i;?>" value="<?=$class->value;?>" disabled="true" size="4"/>
    The code to enable it calls a function.
    Code:
    <img alt="" src="images/img.gif" onclick="disable_enable(<?=$i;?>);"/>
    The function is:
    Code:
    <script type="text/javascript" language="JavaScript">
      function disable_enable($i)
      {
        elements="input_name"+$i;
        document.form.elements.disabled=false;
      }
    </script>
    I've also tried using a getElementById in the onclick and tried using document.form.. . in the onclick and just can't seem to get the textbox to enable. Am I missing something really simple?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    first, disabled is a HTML standalone attribute. if you want to set a value, then use "disabled".

    document.form.e lements is an element collection (but maybe even the document.form call is already invalid*) and as such doesn’t have a .disabled property.

    * - it is good coding practice to not use HTML/CSS/JavaScript keywords as variable names

    Comment

    • KeredDrahcir
      Contributor
      • Nov 2009
      • 426

      #3
      I'm not calling the form form. I'm just using that in place of my form name.

      I'm not sure what you mean by an element collection.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        the same thing that is returned when (for instance) calling document.getEle mentsByName(). document.form_n ame.elements does the same for all form controls in a form.

        Comment

        • KeredDrahcir
          Contributor
          • Nov 2009
          • 426

          #5
          All the websites I've been to tell me that the code is used is correct.
          What is the correct way to re-enable the element?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            set the .disabled property of the form control to false.

            Comment

            • KeredDrahcir
              Contributor
              • Nov 2009
              • 426

              #7
              I need it be disabled to begin with.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                set the disabled attribute and do nothing in JavaScript.

                Comment

                • KeredDrahcir
                  Contributor
                  • Nov 2009
                  • 426

                  #9
                  I thought I needed JavaScript to enable it. How do I enable it without JavaScript?

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    a form control in its default configuration is always enabled. to disable it you either set the disabled attribute in HTML or set in JavaScript the .disabled property to true.

                    Comment

                    • KeredDrahcir
                      Contributor
                      • Nov 2009
                      • 426

                      #11
                      I've set the it as disabled. I want to enable it if the user clicks on the image. That why I want to use JavaScript. I don't want that filed to be posted unless the image has been clicked on.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        then use the click event to set the .disabled property to false.

                        Comment

                        • KeredDrahcir
                          Contributor
                          • Nov 2009
                          • 426

                          #13
                          I've tried that and it's not working. That's why I came here.

                          Comment

                          • KeredDrahcir
                            Contributor
                            • Nov 2009
                            • 426

                            #14
                            Is there anything else I can try?

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              you can try it with a form control object.

                              Comment

                              Working...