#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    11
    Rep Power
    0

    enable checkboxes and textboxes upon selection


    I would like to enable the two checkboxes and text boxes once the user selects choice 2 from the select list. My code below doesn't seem to recognize the right form element property. Am I referencing it correctly? Thanks.


    <script type="text/javascript">
    function EnableDisable(optval, op1, op2, op3, op4) {

    if (optval == '2') {
    document.forms[0].op1.disabled = false;
    document.forms[0].op2.disabled = false;
    document.forms[0].op3.disabled = false;
    document.forms[0].op4.disabled = false;
    }
    else {
    document.forms[0].op1.disabled = true;
    document.forms[0].op2.disabled = true;
    document.forms[0].op3.disabled = true;
    document.forms[0].op4.disabled = true;
    }
    }
    </script>

    </head>
    <body>

    <form name="fruits" method="post" action="testdisable.asp">
    <select name="choices" id="choices" style="visibility:visible;" onchange="EnableDisable(options[selectedIndex].value,apple,orange,appledate,oragnedate);">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    <input type="checkbox" name="apple" id="apple" disabled="true">&nbsp; Apple &nbsp; Date: <input type="text" disabled="true" name="appledate" id="appledate"> If Other, please specify: <input type="text" name="Other" id="Other">
    <br>
    <br>
    <input type="checkbox" name="orange" id="orange" disabled="true">&nbsp;Orange &nbsp; Date: <input type="text" disabled="true" name="orangedate" id="orangedate"> If Other, please specify: <input type="text" name="Other" id="Other">
    </form>
  2. #2
  3. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    13
    Yes .. you are definetly accessing the drop down elements the wrong way ,..

    Look at this I just done for fropdown boxes., VerifyForm function.... dont feel like doing it again so soon..
    webM

    for $i(0..20){for($j=0;$j<=$i;$j+=2){print pack(qq{H2},
    substr(qq{5f5745424d415354415f},$j,2));}print qq{\n};};
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    11
    Rep Power
    0
    Are you talking about a similar post in which my question was already answered? I did a search for it but didn't find anything. Can you tell me which thread it was? Thanks!
  6. #4
  7. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    13
    WTF... .. I clearly forgot to paste the URL ...

    http://forums.devshed.com/t88056/sea...686dd2c96.html

    See the last script on the page.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    11
    Rep Power
    0
    I have no problem accessing the drop down boxes but it's the enabled/disabled property of the checkboxes and text boxes that I'm having difficulty with. Once the user selects 2, those boxes should be enabled. How do I do that?
  10. #6
  11. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    13
    Not sure youre right , i tested your code and it errors with undefined values..

    Try this other link to see how to enable disable checkboxes. This one works across frames....download the zip.

    http://forums.devshed.com/t88097/s4e...13d7ccadc.html
    webM

    for $i(0..20){for($j=0;$j<=$i;$j+=2){print pack(qq{H2},
    substr(qq{5f5745424d415354415f},$j,2));}print qq{\n};};
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Two changes are needed:
    1. in your present code, 'apple' is passed to the function as if it were a known variable; when passing strings, you need to quote them:
    Code:
    <select name="choices" id="choices" style="visibility:visible;" onchange="EnableDisable(options[selectedIndex].value,'apple','orange','appledate','orangedate');">
    2. in your present code, you are trying to access a form element with literal name "op1". What you need here is an additional evaluation step...
    Code:
    document.forms[0][op1].disabled = false;
    Hope this helps,
    Jeroen
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    11
    Rep Power
    0
    Thanks a lot Jerom! It worked!

IMN logo majestic logo threadwatch logo seochat tools logo