disable form element not working in safari

Discussion in 'JavaScript' started by lanmonkey, Jun 19, 2008.

  1. #1
    Hi all

    The following has 2 input elements (a selection list and an input field) and has 2 radio buttons that let the user select which input element they want to use, the unslelected element will get disabled.

    its working fine in IE6 and FF3 but not in sefari.

    <input name="radio" type="radio" value="x" checked="checked" onfocus="document.getElementById('menu1').disabled=false; document.getElementById('field1').disabled=true" />
    
    <select id="menu1" name="menu1" >
    <option selected="selected">unnamed1</option>
    <option>unnamed2</option>
    <option>unnamed3</option>
    <option>unnamed4</option>
    </select>
    
    
    <input name="radio" type="radio" value="y" onfocus="document.getElementById('menu1').disabled=true; document.getElementById('field1').disabled=false"/>
    
    <input id="field1" name="field1" type="text" value="some text" disabled="disabled"/>
    
    <input type="submit" value="go" />
    HTML:
    Anyone have any ideas whats going wrong?
     
    lanmonkey, Jun 19, 2008 IP
  2. jetblack

    jetblack Active Member

    Messages:
    93
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Try like that:

    <form name="form1" action="" method="">
    <input name="radio" type="radio" value="x" checked="checked" onClick="document.form1.menu1.disabled=false; document.form1.field1.disabled=true" />
    
    <select id="menu1" name="menu1" >
    <option selected="selected">unnamed1</option>
    <option>unnamed2</option>
    <option>unnamed3</option>
    <option>unnamed4</option>
    </select>
    
    
    <input name="radio" type="radio" value="y" onClick="document.form1.menu1.disabled=true; document.form1.field1.disabled=false"/>
    
    <input id="field1" name="field1" type="text" value="some text" disabled="disabled"/>
    
    <input type="submit" value="go" />
    </form>
    HTML:
     
    jetblack, Jun 19, 2008 IP
  3. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thanks for the reply

    the problem with that I need my page to be XHTML strict complient, and the following isnt:

    it doesnt allown "name" in a form tag

    which is wht I was using document.getElementById('field1')
     
    lanmonkey, Jun 20, 2008 IP
  4. jetblack

    jetblack Active Member

    Messages:
    93
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #4
    Use "document.forms['form1']" to refer form1:

    <form id="form1" action="" method="">
    <input name="radio" type="radio" value="x" checked="checked" onClick="document.forms['form1'].menu1.disabled=false; document.forms['form1'].field1.disabled=true" />
    
    <select id="menu1" name="menu1" >
    <option selected="selected">unnamed1</option>
    <option>unnamed2</option>
    <option>unnamed3</option>
    <option>unnamed4</option>
    </select>
    
    
    <input name="radio" type="radio" value="y" onClick="document.forms['form1'].menu1.disabled=true; document.forms['form1'].field1.disabled=false"/>
    
    <input id="field1" name="field1" type="text" value="some text" disabled="disabled"/>
    
    <input type="submit" value="go" />
    </form>
    HTML:
     
    jetblack, Jun 20, 2008 IP
  5. lanmonkey

    lanmonkey Active Member

    Messages:
    549
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #5
    jetblack thanks

    your solution worked!
     
    lanmonkey, Jun 20, 2008 IP
  6. jetblack

    jetblack Active Member

    Messages:
    93
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #6
    You're wellcome.
     
    jetblack, Jun 20, 2008 IP