vendredi 4 mars 2016

Displaying "required" in just one checkbox (dynamic display)

I've created a database-driven test with three types of questions - input type = radio, text and checkbox. If I insert required before the closing tag, it works fine for the radio and text questions, but not the checkboxes.

The problem is that each checkbox question has several possible answers - anywhere from three to six. And the number of those choices that are correct answers also varies.

But when I add "required" to the checkbox script, the user has to select EVERY answer in order to proceed to the results page. This is what the code looks like:

<label for="q'.$QID.'-'.$Value.'"><input type="checkbox" name="q'.$QID.'[]" id="q'.$QID.'-'.$Value.'" value="'.$Value.'" **required**> '.$QA.'</label>

I found the HTML5 Required Attribute page, which appears to address this problem. If I understand correctly, you can fix the problem by inserting "required" in just one element. So if you insert it in answer A, a user could presumably choose answers C and D, and everything would work just fine.

If that's correct, then is there a way to make "required" display in just one checkbox, instead of all of them?




Aucun commentaire:

Enregistrer un commentaire