Warm tip: This article is reproduced from stackoverflow.com, please click
forms html javascript

I want to move from one form to another in same html page ,like a question answer quiz page

发布于 2020-03-27 10:28:41

I want to iterate my code in js through the list of options:

option=["1","2","3"]

3 forms to appear: first with the value 1 then when I submit it then next form should appear with value:2

Questioner
Umang Goyal
Viewed
34
Rahul Singh 2019-07-03 23:33

You can use innerHTML property on a div which contains the form you want to update. Whenever the submit button is pressed for a question, call a function to increase the counter. Depending on the counter take what you want to place in the div. Eg.

function updateForm() {
    let element = document.querySelector('.question');
    let htmlToAdd = '<form> ... </form>'
    element.innerHTML = htmlToAdd;
}

A better approach would be to use an array of objects with each object containing information about what is to be added to the HTML.