validate data | Sololearn: Learn to code for FREE!

0

validate data

i have questions in an array that comes from mysql and i need to validate each question is checked i manage to check the first question but the rest i don't know how to validate the rest https://code.sololearn.com/wNev65LHt2i3

2/22/2022 12:02:46 AM

Eric Vazquez

5 Answers

New Answer

+1

Is that jQuery code you wrote inside the PHP code block? I didn't clearly get your intention. It would be nice if you can elaborate further on that.

0

I think you should use a `for loop` instead of `foreach loop` then you can do something for(int i =0; i < answer_length; ) { if(answer [I] is checked) I++; else { // This answer is unchecked // Break out of the loop break; } `answer[I]` is actually a string concatenation of "answer" + i

0

You mean change this?: foreach ($question as $key => $value){}

0

Ok yes it's jQuery, in the 'foreach' i add 90 questions that come from mysql (the proyect is in my computer i only copied the code to show how it looks) and then the user have to answer all of them and then there's a button that says "End test" with JavaScript what i want is if the user doesn't answer the test and click "End test" an alert runs saying "Answer all the questions" when the jQuery runs and if the test is empty the alert runs but if only 1 question is checked and then click the button the test is sent, only when each question is checked with "a" or "b" should be sent

0

Let me try, You have a resultset from MySQL which you output as radio buttons (questions and choices). My idea is to make an array with 90 elements (in JS) and use it to store the selected answer status of each question. You then check the array in case any element were unanswered. That's a really rough idea though, I'm not sure how it's done in jQuery.