First, the hidden selection box corresponding to each problem in the form on the page, and the corresponding problems behind it:
<Label style = "display: none">
<Input type = "checkbox" name = "inquestion" value = "<% = questionId %>" checked = "checked"/>
</Label>
<P> <B> <% = questionName %> </B> </p>
Next, select the button for the answer to each question in the form on the page:
<Input type = "radio" name = "<% = questionId %> answer" value = "<% = resultId %>" align = "absmiddle"/> <% = resultName %>
The button appears after each question. You can have multiple answers and each answer has a corresponding radio, then, when submitting the form, traverse the form to check whether any answer to each question has been selected.
Finally, when submitting the form, use jquery to check the selection:
Function submitForm () {www.2cto.com
Var str = "";
// Obtain the hidden selection box before each problem to obtain the id of the problem
$ ('Input [type = "checkbox"] [name = "inquestion"] '). each (function (){
If (this. checked ){
// Concatenate the question ";"
Str + = $ (this). val () + ";";
}
});
// Split the problem in string
Var ids = str. split (";");
// Obtain the id of each question, construct the Object name of the question answer, and obtain the answer object $ (DOM object) to determine whether to select
For (var I = 0; I <(ids. length-1); I ++ ){
// Obtain the question id
Var qid = ids [I];
// Obtain the answer object
Var transferType = $ ("input [name = '" + qid + "answer']: checked"). val ();
// Determine whether an object is selected
If (transferType = undefined | transferType = null ){
Alert ("no." + (parseInt (I) + 1) + ". Please select .");
Return;
}
}
Document. myform. submit ();
}