Set read only check box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #1

    Set read only check box

    I want to set read only for check box when I click submit button. But my code didn't work. This is my code java script code.
    Code:
    document.getElementsById('check')[0].disabled=true;
    document.getElementsById('check')[1].disabled=true;
    or 
    document.getElementById('check')[0].readOnly=true;
    document.getElementById('check')[1].readOnly=true;
    could someone help me? I'm using php and javascript.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Code:
    document.getElementsById('check')[0]
    should be undefined. getElementsById () is an invalid method call.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      ...and
      Code:
      document.getElementById('check')[0]
      doesn't make sense because it returns a single element. You need to give your elements unique IDs or access them by name.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by acoder
        ...and
        Code:
        document.getElementById('check')[0]
        doesn't make sense because it returns a single element.
        additional info: that call would look for the property "0" of the element with the id "check" and because Elements usually* don’t have such a property, undefined is returned.

        * except when you explicity define such a property

        Comment

        Working...