Forums

JS to manage events in several checkbox CFv5

teldrive 13 Mar, 2014
Answer
I only want to give you feedback about the solution of managing several checkbox using events type function , due to there are very Little information about it in this fórum. This is working.

we have in our form 6 checkbotton, when one is checked others 5 must be unchecked
alert message also advice when user wants uncheck one checked box that is not necessary

First you must to define a function on JavaScript in setup page( load JavaScript)
function ponente(chkBox)
     {
var checkboxs = document.getElementsByClassName("A");
	     if (chkBox.checked)
         {
           chkBox.value = "P"; //put selected as Ponent as intermediate state after will change to True, 
//this is used to avoid confusion with any other box checked as True
         }
         else
         {
alert ("Seleccione directamente otro Autor como Ponente");
         }
for (var i = 0; i <= checkboxs.length - 2; i++) 
    {
   if(checkboxs[i].value=="T")   // put all in false
        {
           checkboxs[i].value = "F";
           checkboxs[i].checked = false;
        }
	if(checkboxs[i].value=="P")   // put selected form ponente to true
	{
      	alert (" Ha seleccionado este autor como Ponente");
	       checkboxs[i].value = "T";
           checkboxs[i].checked = true;
        }
	 }
	 }


Advice: limit of for should be checkboxs.length - 1, but i have a last checkbox of "accept conditions" at bottom pageand by this I set checkboxs.length - 2
i spent some time to identify that class for checkbottom is "A"
This topic is locked and no more replies can be posted.