www.webdeveloper.com
Results 1 to 4 of 4

Thread: Disabling checkboxes

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Disabling checkboxes

    Hello,

    I am creating a form using a system called SORCE. The system does not allow the use of radio buttons, only check boxes.

    I have three checkboxes and want to disable the other 2 when one of them is checked. I have ability to enter javascript code behind each checkbox and there is already some code behind each check box. Below is an example of the code behind the first check box:

    function do_value_toggle_54740(oCurObj)
    {
    oForm=oCurObj.form
    if (oForm.value_toggle_54740_0.checked)
    oForm.value_toggle_54740.value=oForm.value_toggle_54740_checkedval.value
    else
    oForm.value_toggle_54740.value=oForm.value_toggle_54740_uncheckedval.value;
    // do not alter code above this line ! put your call in after these comments
    // you may add more parameters to the call to this function
    // remember all changes are lost if you delete this value_toggle
    }
    I have tried adding the other checkboxes to the if statement, but this just causes errors on the form.

    The 2nd check box is called value_toggle_54743 and the third is called value_toggle_54746.

    What javascript can i add behind each check box to disable the other two when one is clicked? If any at all.

    Many thanks

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by g00dfella92 View Post
    What javascript can i add behind each check box to disable the other two when one is clicked? If any at all.
    But that is exactly the definition of a group of radio buttons. What don't you use radio buttons instead of checkboxes? No javascript code is needed for that

  3. #3
    Join Date
    Nov 2011
    Posts
    2
    Hello, thanks for your reply .

    As I mentioned in my question, the software does not allow the use of radio buttons.

    Thanks.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    OK, here's an example:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function attachClickCheckboxes(){
    var names=['value_toggle_54740','value_toggle_54743','value_toggle_54746'], c, i=0;
    while(c=document.getElementsByName(names[i++])[0]){
    c.names=names;
    c.onclick=handleCheckboxes;
    }
    }
    function handleCheckboxes(){
    var names=this.names, c, i=0;
    while(c=document.getElementsByName(names[i++])[0]){
    c.disabled=this.checked;
    }
    this.disabled=false;
    }
    onload=function(){
    attachClickCheckboxes();
    }
    </script>
    </head>
    <body>
    <form action="">
    <input type="checkbox" name="value_toggle_54740" value="54740">
    <input type="checkbox" name="value_toggle_54743" value="54743">
    <input type="checkbox" name="value_toggle_54746" value="54746">
    </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles