I am making a 'quiz website' for a school project but I am kind off stuck with one part.
We need to add questions to a quiz, so I want to make a button "Add Question" which adds 1 (or more) html form(s).
I have little JavaScript experience, and know just the basics.
My Laravel .blade file:
{{ Form::open(array('url'=>'quizzes/edit', 'class' => 'createquiz')) }}
<p>Question 1</p>{{ Form::text('', null, array('placeholder' => 'Question 1', 'size' => '40', 'id' => 'questions')) }}
<p>Question 2</p>{{ Form::text('', null, array('placeholder' => 'Question 2', 'size' => '40', 'id' => 'questions')) }}
<p>Question 3</p>{{ Form::text('', null, array('placeholder' => 'Question 3', 'size' => '40', 'id' => 'questions')) }}
<p>Question 4</p>{{ Form::text('', null, array('placeholder' => 'Question 4', 'size' => '40', 'id' => 'questions')) }}
<br>
<br>
{{ Form::button('Add Question', array('onclick' => 'addQuestion()', 'id' => 'questionadd')) }}
{{ Form::submit('Edit Quiz') }}
{{ Form::close() }}
My JavaScript:
function addQuestion() {
var node = document.createElement('FORM');
var counter = 1;
var limit = 3;
if (counter == limit) {
alert("You have reached the limit of questions");
}
else {
node.appendChild(FORM);
document.getElementById("questions").appendChild(node);
}
}
So on click of the "Add Question" button I want to have one question added right after the others