I am generating questions from a database where the user will select answer in a drop-down menu.When a user selects a certain option,a suggestion will be pushed to the array triggering on-change event of JavaScript. When the user has completed all the questions i will then send the array as a row to a database from form storing all the suggestions.
When i try to send the suggestion.The suggestion gets pushed the first time.But when a user changes the answers the array gets pushed again with duplicate message
var suggestions=[];
function sendSuggestion() {
if (document.getElementById("1").value == "no" && document.getElementById("2").value == "no" ){
suggestions.push("you need to study more");
}
}
</script>
<form action="">
@foreach ($questions as $question)
{{-- <p>{{$question->id}}){{$question->english}}</p> <br> --}}
<div class="form-group">
<label>{{$question->id}}) {{$question->english}}</label>
<select id="{{$question->id}}" onchange="sendSuggestion()" class="form-control" id>
<option value="yes">Yes</option>
<option value="no">No</option>
<option value="regularly">Regularly</option>
<option value="sometimes">Sometimes</option>
</select>
</div>
@endforeach
</form>
i expect output of "you need to study more" when a user selects no in question with id 1 and 2.