I already saw this question however, it didn't work for me whatever I tried.
My function is:
function validatePreviousChecked(parent, child) {
found = false;
element = document.getElementsByName(parent);
for (i = 0; i < element.length; i++) {
if (element[i].checked == true) {
found = true;
}
}
if (!found) {
alert("Please answer the questions in order. It seems that you didn't answer a previous question");
document.getElementsByName(child).checked = false;
return false;
}
return true;
}
function disableAll(elements) {
var myelements = document.getElementsByName(elements);
for ( var i = 0; i < myelements.length; i++) {
myelements[i].disabled = true;
}
return true;
}
and my radio button:
<input onclick="javascript: if(validatePreviousChecked('q1_financial_product','q1_product_likelihood[0]')){disableAll('q1_product_likelihood');}" value="1" name="q1_product_likelihood" type="radio" />
However, the first function is being executed, returning true (I validated it) but never the second one!
What is wrong?
EDITED
This is another snippet:
<input
value="1" name="q1_financial_product"
onclick="disableAll
('q1_financial_product')"
type="radio" />