Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Проверка отметки radiobutton не работает (https://javascript.ru/forum/dom-window/10869-proverka-otmetki-radiobutton-ne-rabotaet.html)

boris2000 27.07.2010 22:48

ура!!!!получилось!!!!
вот так:
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

// основная функция проврки и отправки формы
function CallOnSubmit(){
var string4notice = "";
// массив с именами обязательных к заполнению radiobutton
var obligatory_radiobutton_array = ["articletype", "studycoverage", "studysampling", "studiedpopulationage", "studiedpopulationsex", "studiedpopulationurbanicity", "studydesign", "studyfollowup", "otherriskfactors"];
var obligatory_radiobutton_names_array = ["Article type", "Study population coverage", "Study sampling strategy", "Studied population age", "Studied population sex", "Studied population urbanicity", "Study design", "Does study include follow-up", "Do risk factors for CKD in studied population are reported"];

var elements = document.forms["aef"].elements;
var element;
	
for(j = 0; j < obligatory_radiobutton_array.length; j++) {
	element = elements[obligatory_radiobutton_array[j]];
	if(getSelectedRadio(element) == -1){
		string4notice = string4notice + "\n\r" + obligatory_radiobutton_names_array[j];
	}
}


if(string4notice != ""){
	string4notice = "Please note the following questions have to be answered before Abstract estimation form submission:" + "\n\r" + string4notice;
	alert (string4notice);
}

	return false;
}


Часовой пояс GMT +3, время: 10:56.