Jquery implements the selection box/selected button in the form to check whether or not the traversal is selected (submit the selection questions and answers on the page)

Source: Internet
Author: User
First, the hidden selection box corresponding to each problem in the form on the page, and the problem following it: & lt; labelstyle & quot; display: none & quot; & gt; & lt; inputtype & quot; checkbox & quot; name & quot; inquestion & quot; value & quot; & lt; % quest

First, the hidden selection box corresponding to each problem in the form on the page, and the corresponding problems behind it:



<% = QuestionName %>


Next, select the button for the answer to each question in the form on the page:
<% = 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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.