-1

私の検証にわずかな問題があります。私がやりたいのは、一番下に検証メッセージを表示して、すべての行が最初に追加されたことを確認したいということです。すべての質問が追加され、その検証に合格した場合にのみ、個々の質問の検証が表示されます。たとえば、少なくとも 1 つの回答を選択してください、または必要な数よりも少ない回答を選択したなどです。

現時点では、たとえば、少なくとも1つの回答を選択する必要があると述べており、これがソートされると、残りの質問を追加する必要があると述べているなど、逆の方法で行っています。

function validation() {

    var marks = parseInt($("#total-weight").text());
    var _qid = "";
    var _msg = "";

    var maxQuestions = <? php echo(int) $_SESSION['textQuestion']; ?> ;
    var questionsAdded = $('tr.optionAndAnswer').length;

    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function () {

        _qid = $("td.qid", this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".numberAnswerTxtRow", this).each(function () {
            var currenttotal = $(this).closest('.optionAndAnswer').find('.answerBtnsOn').length;

            if ($(this).val() == 0) {
                alertValidation += "\n\u2022 You have not selected an answer, please select at least one answer\n";
            } else if (currenttotal < $(this).val()) {
                alertValidation += "\n\u2022 You have selected less answers than the required amount\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });

    });



    if (alertValidation == "") {
        if (questionsAdded < maxQuestions) {
            _msg = '';
            alertValidation = ("You Have Not Added in All of Your Questions \n\n\u2022 You have " + (maxQuestions - questionsAdded) + " Questions Remaining:");
        }
    }

    if (alertValidation != "") {
        alert(_msg + alertValidation);
        return false;
    }

    return true;
}

以下はコード全体です - 以下のコードでは、最初に残りの質問の数が検証に合格するまで、他の検証メッセージは表示されません。$(".numberAnswerTxtRow",this).each(function() {私が言及したような唯一の問題は、else if を含む他の関数の唯一の関数でもある内の検証です。

function validation() {

    var marks = parseInt($("#total-weight").text());
    var _qid = "";
    var _msg = "";

    var maxQuestions = <? php echo(int) $_SESSION['textQuestion']; ?> ;
    var questionsAdded = $('tr.optionAndAnswer').length;

    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function () {


        _qid = $("td.qid", this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".textAreaQuestion", this).each(function () {



            if (!this.value || this.value.length < 5) {
                alertValidation += "\n\u2022 You have not entered a valid Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });

        $(".numberAnswerTxtRow", this).each(function () {


            var currenttotal = $(this).closest('.optionAndAnswer').find('.answerBtnsOn').length;

            if ($(this).val() == 0) {
                alertValidation += "\n\u2022 You have not selected an answer, please select at least one answer\n";
            } else if (currenttotal < $(this).val()) {
                alertValidation += "\n\u2022 You have selected less answers than the required amount\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }

        });

        $(".txtWeightRow", this).each(function () {


            if (!this.value) {
                alertValidation += "\n\u2022 Please enter in a figure for Number of Marks for this Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        if (alertValidation != "") {
            return false;
        }
    });

    if (alertValidation == "") {

        if (questionsAdded < maxQuestions) {
            _msg = '';
            alertValidation = ("You Have Not Added in All of Your Questions \n\n\u2022 You have " + (maxQuestions - questionsAdded) + " Questions Remaining:");
        }



    }

    if (alertValidation != "") {
        alert(_msg + alertValidation);
        return false;
    }

    return true;
}
4

1 に答える 1

1

私があなたの問題を解決した場合、これはあなたがしなければならないことです:

$questions = array();

while ($selectedstudentanswerstmt->fetch()) {

    //Check if the student data exist.
    if (!isset($questions[$detailsStudentId])) {
        $questions[$detailsStudentId] = array(
            'studentalias' => $detailsStudentAlias,
            'studentforename' => $detailsStudentForename,
            'studentsurname' => $detailsStudentSurname,
            'questions' => array();
        );
    }

    $questions[$detailsStudentId]['questions'][$detailsQuestionId] = array(
        'questionno'=>$detailsQuestionNo,
        'content'=>$detailsQuestionContent,
        'optiontype'=>$detailsOptionType,
        'noofanswers'=>$detailsNoofAnswers,
        'answer'=>$detailsAnswer,
        'replytype'=>$detailsReplyType,
        'questionmarks'=>$detailsQuestionMarks,
        'studentanswer'=>$detailsStudentAnswer,
        'responsetime'=>$detailsResponseTime,
        'mouseclick'=>$detailsMouseClick,
        'studentmark'=>$detailsStudentMark
    );

}

次に、配列を非常に簡単に反復できます。

foreach ($questions as $studentId => $studentData) {
    echo $studentData['studentAlias'].' - '.$studentData['studentforename'].' '.$studentData['studentsurname'].'<br/>';

    foreach ($studentData['questions'] as $questionId => $questionData) {
        echo '<strong>'.$questionData['questionno'].': '.$questionData['content'].'<br/>';
        echo $questionData['optiontype'].' - '.$questionData['noofanswers'].' - '.$questionData['answer'].' - '.$questionData['replytype'].' - '.$questionData['questionmarks'].'<br/>';
        echo $questionData['studentanswer'].' - '.$questionData['responsetime'].' - '.$questionData['mouseclick'].' - '.$questionData['studentmark'].'<br/>';
    }
}

これはあなたが探しているものですか?

于 2013-02-08T16:23:46.557 に答える