Disable dropdown

Discussion in 'PHP' started by ishandoshi, Jul 29, 2009.

  1. #1
    Hii,
    I have 2 options in my form:
    1)Enter new Subject
    2)Enter new Chapter

    When 1st is selected,i want that automatically the 2nd dropdown should be disabled.

    Can anyone pls help me?
    Thnx a lot in advance :)
     
    ishandoshi, Jul 29, 2009 IP
  2. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    <html>
    <head>
    
    </head>
    <body>
     <select id="subject" onchange="this.value != ''? document.getElementById('chapter').disabled=true : document.getElementById('chapter').disabled=false; ">
      <option value=""></option>
      <option value="sub1">Subject1</option>
      <option value="sub2">Subject2</option>
      <option value="sub3">Subject3</option>
     </select>
    
     <select id="chapter">
      <option value=""></option>
      <option value="chap1">Chapter1</option>
      <option value="chap2">Chapter2</option>
      <option value="chap3">Chapter3</option>
      </select>
    </body>
    </html>
    PHP:
     
    Martinoes, Jul 29, 2009 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    i don't think this is going to work, and if not i have the repleaced code for the onchange=""

    this.options[this.selectedIndex].value != ''? document.getElementById('chapter').disabled=true : document.getElementById('chapter').disabled=false;
     
    EricBruggema, Jul 29, 2009 IP
  4. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this.value != '' is the same as this.options[this.selectedIndex].value != '' i think. besides i test this code and it works just fine.
     
    Martinoes, Jul 29, 2009 IP
  5. ishandoshi

    ishandoshi Active Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Hey thnx a lot guys!!
    It really helped and made it working :)
    U guys rock!!
     
    ishandoshi, Jul 29, 2009 IP