Подскажите что делаю не так.
Есть форма, и надо проверить во всех ли группах radiobutton пользователь сделал отметку (любую? главное чтобы все отметил). Скрипт прилагаю - не работает!
// сперва функция проверки radiobutton
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
// основная функция проврки и отправки формы
function CallOnSubmit(){
// массив с именами обязательных к заполнению 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 string4notice = "";
for(j = 0; j <= obligatory_radiobutton_array.length; j++) {
if (getCheckedValue(document.forms['aef'].elements[obligatory_radiobutton_array[j]]) = ""){
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;
confirm (string4notice);
}
return false;
}
код формы
<form action="examination_step2.php" method="post" name="aef" target=_parent>
<BUTTON TYPE = BUTTON ONCLICK="CallOnSubmit();">Check</BUTTON><br>
<div class="abstract_estimation_list"><label><input type="radio" name="studydesign" value="1" />case-control study</label><br />
<label><input type="radio" name="studydesign" value="2" />cross-sectional study</label><br />
<label><input type="radio" name="studydesign" value="3" />retrospective cohort study</label><br />
<label><input type="radio" name="studydesign" value="4" />prospective cohort study</label><br />
<label><input type="radio" name="studydesign" value="5" />randomized controlled trial</label><br />
<label><input type="radio" name="studydesign" value="6" />registry report</label><br />
<label><input type="radio" name="studydesign" value="0" />not reported</label><br /></div>
...
и так далее для каждой группы перечисленной в массиве obligatory_radiobutton_array
...
</form>