PDA

View Full Version : Please help with checkbox Javascript function



deziner76hd
05-05-2012, 02:01 PM
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?


<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

vwphillips
05-05-2012, 03:06 PM
<!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>

deziner76hd
05-05-2012, 04:21 PM
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

deziner76hd
05-06-2012, 04:30 PM
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


<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


onclick="checkI();"

Thank you for any help
If anyone is interested I can give you a login to the back end.