Results 1 to 4 of 4

Thread: Please help with checkbox Javascript function

  1. #1
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Please help with checkbox Javascript function

    Hello,
    My form is located here on page three of the multi form:
    http://www.rocpinions.com/main-form.html

    I have been working on this for days and can't figure it out.
    I have four check boxes. Dog, Cat, Other, None of These. If Dog Cat and Other are checked that is fine but if the check box "None of These" is checked I need it to remove the checks from All other boxes.

    This is an example of exactly what I need my form to do jsfiddle.net/srEuM/

    Does anyone know how I can accomplish this with RS Form Pro?

    Code:
    <script type="text/javascript">
    function checkI()
    {
     checkL = document.getElementsByName('form[PetsInHouse][]');
       for (i=0;i<(checkL.length-1);i++)
         if(document.getElementById('PetsInHouse3').checked)
          document.getElementById('PetsInHouse'+i).disabled = true;
         else document.getElementById('PetsInHouse'+i).disabled = false;
    }
    </script>
    I am currently using this code above and it only disables all checkboxes when "None of These" is checked but if I check any of the other boxes I can still check "None of These" and that is not the correct functionality.
    This is exactly what I need to do but in the same format I have above.
    http://jsfiddle.net/srEuM/

    Any help would be greatly appreciated.
    Thank you
    Deziner

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    function checkI()
    {
     var checkL = document.getElementsByName('form[PetsInHouse][]');
       for (var i=0;i<checkL.length-1;i++)
         if(document.getElementById('PetsInHouse3').checked){
          document.getElementById('PetsInHouse'+i).disabled = true;
          document.getElementById('PetsInHouse'+i).checked = false;
         }
         else {
          document.getElementById('PetsInHouse'+i).disabled = false;
         }
    }
    </script></head>
    
    <body>
    		<div class="formCaption2">Which of the following pets do you have? Check all that apply.<strong class="formRequired">*</strong></div>
    		<div class="formBody"><input  name="form[PetsInHouse][]" type="checkbox" value="Dog" id="PetsInHouse0" onclick="checkI();" /><label for="PetsInHouse0">Dog</label><br/><input  name="form[PetsInHouse][]" type="checkbox" value="Cat" id="PetsInHouse1" onclick="checkI();" /><label for="PetsInHouse1">Cat</label><br/><input  name="form[PetsInHouse][]" type="checkbox" value="Other" id="PetsInHouse2" onclick="checkI();" /><label for="PetsInHouse2">Other</label><br/><input  name="form[PetsInHouse][]" type="checkbox" value="None" id="PetsInHouse3" onclick="checkI();" /><label for="PetsInHouse3">None</label><br/><span class="formClr"><span id="component52" class="formNoError">Invalid Input</span></span></div>
    
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    deziner76hd (05-05-2012)

  4. #3
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post

    Thank you for your help!
    I am using RS Form Pro I have used the Javascript modification you suggested but I get the same result as before in MY form.
    Your form works exactly as I need when I put it in dreamweaver and view in a browser.

    My form is located here on page three of the multi form:
    http://www.rocpinions.com/main-form.html

    I changed my Javascript to your modification but I am still getting the same result I was. Any other suggestions on how I can fix this?

    I have tried to get an answer in the RS forums for a couple days with no response.

    Thank you
    Gary

  5. #4
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ok all I need this to do now is when anything other than None is checked None can not be checked.

    This script works perfect at http://www.rocpinions.com/pet_in_house.html

    But I need it to work in RS Form Pro here http://www.rocpinions.com/main-form.html

    Location of form
    Page 3 of multi form http://www.rocpinions.com/main-form.html
    Dog
    Cat
    Other
    None

    Script I am using

    Code:
    <script type="text/javascript">
    function checkI()
    {
     var checkL = document.getElementsByName('form[PetsInHouse][]');
       for (var i=0;i<checkL.length-1;i++)
         if(document.getElementById('PetsInHouse3').checked){
          document.getElementById('PetsInHouse'+i).disabled = true;
          document.getElementById('PetsInHouse'+i).checked = false;
         }
         else {
          document.getElementById('PetsInHouse'+i).disabled = false;
         }
    }
    </script>
    In additional attributes

    Code:
    onclick="checkI();"
    Thank you for any help
    If anyone is interested I can give you a login to the back end.
    Last edited by deziner76hd; 05-06-2012 at 04:55 PM. Reason: additional info

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
  •