D
D
dimonfreeman2021-06-12 10:11:26
JavaScript
dimonfreeman, 2021-06-12 10:11:26

How to loop through input+textarea from each question and write everything to an array?

We have a list of questions (where there is a question itself, and two fields are an assessment and a textarea). When submitting, you need to somehow form an array so that you can then parse it in the opposite direction and understand which question is which answer.:
I suppose it should go something like this
[Question1[score:2,text:textarea],
Question2[score: 1,text:textarea]]

An example of the layout of the first question.

<label class="form-text-field">
<span class="form-text-quiz-field__label">Текст вопроса номер 1?</span> 
<div class="rating-area q1">
<input id="q1-star-5" type="radio" name="q1" value="5"> 
<label for="q1-star-5" title="5">5</label> <input id="q1-star-4" type="radio" name="q1" value="4"> 
<label for="q1-star-4" title="4">4</label> <input id="q1-star-3" type="radio" name="q1" value="3"> 
<label for="q1-star-3" title="3">3</label> <input id="q1-star-2" type="radio" name="q1" value="2"> 
<label for="q1-star-2" title="2">2</label> <input id="q1-star-1" type="radio" name="q1" value="1"> 
<label for="q1-star-1" title="1">1</label></div> 
<input placeholder="Comment" name="q1" type="textquiz" display="true" autoload="true"  class="form-text-field__input"> <!----></label>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-06-12
@dimonfreeman

  1. Find all label.form-text-fieldwith querySelectorAll().
  2. Convert to array[...allLabels]
  3. Iterate over this array map(), forming from the next labelelement of the output array with texts
Try to start writing, then contact if you get stuck.
An example of getting the selected radio value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question