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 Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post

    If object is 1 then object 2 is disabled? Forms

    What i would like to do is this, and i am not experienced in javascript!

    If aname1 = 1 then then aname2 then disabled
    If aname1 = 2 then then aname2 = enabled

    ========

    <select name="aname1" id="type">
    <option selected>1</option>
    <option>2</option>
    </select>

    ========

    <input type="Text" name="aname2" size="10" maxlength="9">


    i had this, which didn't work
    PHP Code:
    if(document.forms[0].chan.value=="1")
    {
    document.forms[0].aname2.disabled=true


  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    <form name=myform>
    <select name=aname1 id=aname1 onchange="dis();">
    <option value='1'>1</option>
    <option value='2'>2</option>
    </select>
    <input type="Text" id=aname2 name="aname2" size="10" maxlength="9" disabled=enabled>
    </form>



    <script type=text/javascript>
    function dis(){
    if (document.all || document.getElementById){
    if (document.myform.aname1.value=='1')
    document.myform.aname2.disabled=true
    else
    document.myform.aname2.disabled=false
    }
    }
    </script>



    hope this helps.....
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Perfect Thanks

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,315
    Thanks
    29
    Thanked 279 Times in 273 Posts
    Edit: Heh, I see a reply now after having posted. Guess I shouldn’t have left the tab open so long.

    Quote Originally Posted by reyna12 View Post
    <select name="aname1" id="type">
    Values for the name and id attributes must match.

    Quote Originally Posted by brandonH View Post
    <input … disabled=enabled>
    The disabled attribute does not have an “enabled” value.

    Here’s the code a bit refined:
    Code:
    JavaScript\:
    function status() {
      var textField = document.getElementById("aname2");
      if (document.getElementById("aname1").value == "1") textField.disabled = true;
      else textField.disabled = false;
      }
    
    HTML:
    <select id="aname1" onchange="status();">
      <option selected>1</option>
      <option>2</option>
    </select>
    
    <input type="text" id="aname2" size="10" maxlength="9" disabled>
    Last edited by Arbitrator; 11-07-2006 at 03:47 PM.
    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
    •