SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    enable/disable checkboxes

    Hi Guys!

    I have written the following script which enables/disables checkboxes on my page when a radio button is selected.

    Code JavaScript:
    <script language="JavaScript" type="text/javascript">
    <!--
    function disableCheckboxes(){
    	document.watching.notify_1.disabled = true;
    	document.watching.notify_2.disabled = true;
    	document.watching.notify_3.disabled = true;
    }
     
    function enableCheckboxes(){
    	document.watching.notify_1.disabled = false;
    	document.watching.notify_2.disabled = false;
    	document.watching.notify_3.disabled = false;
    }
    //-->
    </script>

    What I would like to do is create another function called checkval() like below, which will check the value of my radio button (id: email_alerts). If the value is equal to "on" then it will run enableCheckboxes().

    Anyone know how I can do it? I need to do something like this:

    Code JavaScript:
    checkVal(){
    if(document.watching.email_alerts[0].value = "on"){
    enableCheckboxes();
    }
    }

    What would be the proper syntax?

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    May be ...
    Code JavaScript:
    function checkVal()
    {
        if (document.watching.email_alerts[0].checked)
        {
            enableCheckboxes();
        }
    }

    It's based on the "checked" property. The "on" value is send when summiting the page i think.

    See you

  3. #3
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here is a script that allows you to enable/disable several checkboxes when you click a radio button.

    Code :
    <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
     
    <head>
     
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Enable/Disable Checkboxes</title>
    <script type="text/javascript">
    <!--
    function chgCheckboxes(numbr)
      { var changeState=(numbr==1)? false : true;
        for(var i=1;i<4; i++){ document.watching["notify_"+i].disabled = changeState; }
       }
    //
    //-->
    </script>
    <style type="text/css">
    <!--
    body     { font-family:arial, helvetica, sans-serif; font-weight:bold; font-size:13px; color:#000; text-align:center; margin:3px 0px; }
    form     { width:300px; }
    form p   { margin-top:0px; margin-bottom:5px; }
    fieldset { text-align:left; }
    #wrap    { position:relative; top:20px; left:0px; width:900px; height:500px; margin:0px auto; text-align:left; }
    .m10     { margin-top:10px; }
    -->
    </style>
    </head>
     
    <body onload="chgCheckboxes(2)">
     
    <div id="wrap">
      <form name="watching">
        <fieldset>
        <legend>Checkboxes</legend>
        <p class="a"><input type="checkbox" name="notify_1" value="BBB"> Notify 1<p>
        <input type="checkbox" name="notify_2" value="BBB"> Notify 2</p>
        <p><input type="checkbox" name="notify_3" value="BBB"> Notify 3</p>
        </fieldset>
        <p class="m10">
        <input type="radio" name="eAlert" value="1" onclick="chgCheckboxes(1)"> 
        Email alerts</p>
        <p>
        <input type="radio" name="eAlert" value="2" checked onclick="chgCheckboxes(2)"> 
        No Email alerts</p>
      </form>
      <!-- end form -->
    </div>
    <!-- end wrap -->
     
    </body>
     
    </html>


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
  •