My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How to call javascript onclick event on button function in PHP

Rishabh Dwivedi's photo
Rishabh Dwivedi
·Mar 20, 2019
<form role="form" id="next_question" method="post">
<button type="button" name="next_button" id="next_button" class="btn btn-primary btn-lg" onclick="nextQuestion();" >Next</button>
</form>

How to write this JavaScript code in PHP?

function nextQuestion() {   
                let quest = document.getElementById('question').innerHTML;
                ques_list.push(quest);
                answer_list.splice(counter-1, 1, radio_id);
                getQuestion();
                counter++;
                if(counter >= 10) {
                    result_button='<button type="button" name="end_button" id="end_button" class="btn btn-primary" onclick="submitAnswer();" >Submit Answers</button>'
                    document.getElementById('button_group').innerHTML=result_button;
                }
            }