Professional Web Applications Themes

Javascript problem - Macromedia Dynamic HTML

Hi Guys, I'm trying to disable input fields by clicking a radio button, however I cannot get this to work, can anyone help? Thankyou <script type="text/javascript"> function toggleVisibility(controlId) { var control = doent.getElementById(controlId); if(control.disabled == true){ control.disabled == false; } else{ control.disabled == true; } } </script> <input type="radio" name="type" id="ft" value="ft" onclick="toggleVisibility('r1');" /> <input type="radio" name="type" id="pt" value="pt" onclick="toggleVisibility('r1');" /> <input type="text" name="coursecode" id="r1" size="25" maxlength="100" value="" >...

  1. #1

    Default Javascript problem

    Hi Guys,

    I'm trying to disable input fields by clicking a radio button, however I
    cannot get this to work, can anyone help?

    Thankyou



    <script type="text/javascript">

    function toggleVisibility(controlId)

    {

    var control = doent.getElementById(controlId);

    if(control.disabled == true){
    control.disabled == false;
    }
    else{
    control.disabled == true;
    }


    }

    </script>
    <input type="radio" name="type" id="ft" value="ft"
    onclick="toggleVisibility('r1');" />

    <input type="radio" name="type" id="pt" value="pt"
    onclick="toggleVisibility('r1');" />

    <input type="text" name="coursecode" id="r1" size="25" maxlength="100"
    value="" >

    Mattastic Guest

  2. #2

    Default Re: Javascript problem

    Mattastic wrote: 

    Are you trying to disable them or control their visibility? The function
    you're using is called toggleVisibility(), but it uses the disabled
    attribute, which doesn't control visibility.

    The reason your function doesn't work is because you're using double
    equals signs when trying to set the new value. The function should look
    like this:

    function toggleVisibility(controlId)
    {
    var control = doent.getElementById(controlId);

    if(control.disabled){
    control.disabled = false;
    } else{
    control.disabled = true;
    }
    }

    However, if it's visibility you want to control, it should be this:

    function toggleVisibility(controlId)
    {
    var control = doent.getElementById(controlId);

    if(control.style.visibility == "visible"){
    control.style.visibility = "hidden";
    } else{
    control.style.visibility = "visible";
    }
    }

    --
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/
    David Guest

  3. #3

    Default Re: Javascript problem

    Double == means comparison, not equate.

    Reduce to one equals sign in your two assignments.

    Or toggle using control.disabled != control.disabled.
    akribie Guest

  4. #4

    Default Re: Javascript problem

    Ah of course thanks fellas!

    It works great for a single input field, however, I need to disable various
    inputs, can I pass a list of ID's to a javascript function as a list? Then loop
    through them to hide them?

    Thanks again


    Mattastic Guest

  5. #5

    Default Re: Javascript problem

    Would something similar to this work?:



    <script type="text/javascript">

    function toggleShow(controlId)
    {
    for(i=0; i< controlId.length; i++)
    {
    var getid = "r" + i;
    var control = doent.getElementById('getid');
    control.disabled = true;
    }
    }


    function toggleHide(controlId)
    {
    for(i=0; i< controlId.length; i++)
    {
    var getid = "r" + i;
    var control = doent.getElementById('getid');
    control.disabled = false;
    }
    }
    </script>
    <input type="radio" name="type" id="ft" value="ft"
    onclick="toggleShow('r1,r2,r3,r4,r5,r6,r7,r8,r9,r1 0,r11,r12,r12,r14');" />

    <input type="radio" name="type" id="pt" value="pt"
    onclick="toggleHide('r1,r2,r3,r4,r5,r6,r7,r8,r9,r1 0,r11,r12,r12,r14');" />

    Mattastic Guest

Similar Threads

  1. javascript problem!
    By jmack159 in forum Macromedia Dynamic HTML
    Replies: 2
    Last Post: March 8th, 08:38 PM
  2. javascript problem in CF 7 MX and IE 6.0
    By Manweevil in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: June 13th, 03:12 PM
  3. PHP & Javascript problem
    By daniel in forum PHP Development
    Replies: 1
    Last Post: October 27th, 07:51 PM
  4. javascript problem
    By Dwayne Epps in forum Macromedia Dreamweaver
    Replies: 6
    Last Post: July 18th, 06:29 PM
  5. Javascript Problem in IE
    By Ray Yiu in forum Windows XP/2000/ME
    Replies: 2
    Last Post: July 9th, 01:44 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139