Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disabling text boxes

    I have the following text box and button:
    Code:
    <input type="text" name="ContainerCode" maxlength="50"/>
    <input type="button" name="Container_additem" value="..." onclick="Popup('ContainerCode');"/>
    And the following checkbox and function:
    Code:
    <input name="independentBox" type="checkbox" onclick=check_independent_status() value="0"/>
    
    function check_independent_status() {
    					if(document.BarCodeForm.independentBox.checked==1)
    {document.BarCodeForm.Container_additem.disabled= true;
    document.BarCodeForm.ContainerCode.disabled= true;}
    else{
    document.BarCodeForm.ContainerCode.disabled= false;
    document.BarCodeForm.Container_additem.disabled= false;}
    				}
    When I click the checkbox, I want both the text box and button to be disabled. However, only the button is getting disabled in IE with no errors thrown. In Firefox, it works perfectly! What am I missing here???
    Last edited by greenspacechunk; 07-12-2007 at 06:58 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Is there any error message? Look at the status bar if it has the "!" icon and then double-click it.

    BTW, the code can be simplified like this.
    Code:
    <input name="independentBox" type="checkbox" onclick="check_independent_status(this)" value="0" />
    
    function check_independent_status(oChk) {
      oChk.form.Container_additem.disabled = oChk.checked;
      oChk.form.ContainerCode.disabled = oChk.checked;
    }

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    could be some syntax errors

    1. The XHTML end code needs a space before the slash:
    Code:
    <tag />
    2. Better nest the handler into quotes:
    Code:
    ...onclick="check_independent_status()"...
    3. Special characters might bring errors when used in name. Better use JSON:
    Code:
    document['form_name']['element_name']
    4. You may use the this self reference and use straight the Boleean values

    Try this (untested):
    Code:
    <input name="independentBox" type="checkbox" onclick="check_independent_status(this)" value="0" />
    ...........
    function check_independent_status(c) {
    c.form['Container_additem'].disabled=c.checked;
    c.form['ContainerCode'].disabled=c.checked;
    }
    And, important: If you have an XHTML Doctype, the embeded javascript code must be isolated inside a CDATA island (to prevent XML conflicts)
    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    ... your code here ...
    /*]]>*/
    </script>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Quote Originally Posted by Kor View Post
    3. Special characters might bring errors when used in name. Better use JSON:
    Code:
    document['form_name']['element_name']
    One could also use the DOM. The name attribute is deprecated for use on the form element anyway.

    Code:
    document.getElementById(elementId)
    Alternatively:

    Code:
    document.getElementsByName(elementName)[index]
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

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