1

I am creating a form right now with which an event (e.g. concernt) can be created. Since I need a lot of information from the user, I looked for a multi-step form and found this one here. I now have the form but I don't know how to call a new page once the form is submitted.

<form action="....." method="post" id="createEvent">

From my understanding the new page that is called has to be in the action parameter of the form, but I tried giving it the path of a different cshtml page with no luck.

function nextPrev(n) {
    // This function will figure out which tab to display
    var x = document.getElementsByClassName("tab");
    // Exit the function if any field in the current tab is invalid:
    if (n == 1 && !validateForm()) return false;
    // Hide the current tab:
    x[currentTab].style.display = "none";
    // Increase or decrease the current tab by 1:
    currentTab = currentTab + n;
    // if you have reached the end of the form... :
    if (currentTab >= x.length) {
        //...the form gets submitted:
        document.getElementById("createEvent").submit();
        return false;
    }
    // Otherwise, display the correct tab:
    showTab(currentTab);
}

This is the function from w3schools, and the comments say it is submitted with the document.getElementById("createEvent").submit(); but nothing happens. Shouldn't this then call the action from the form-tag?

Since there is little explanation on the w3schools page, I thought I'd ask here, maybe someone else understands javascript more than I do.

bogii
  • 11
  • 1
  • Does this answer your question? [Redirecting from cshtml page](https://stackoverflow.com/questions/17653736/redirecting-from-cshtml-page) – Yogi Oct 31 '22 at 20:07
  • `I now have the form but I don't know how to call a new page once the form is submitted.`You can call a new page in the backend action.Or you can you ajax to call the backend action,and then call the new page in ajax success. – Yiyi You Nov 01 '22 at 01:54
  • `document.getElementById("createEvent").submit();` I test with the code,and it will go to the action with form tag,maybe you can click F12,and check when clicking the button,if it will send a request. – Yiyi You Nov 02 '22 at 06:36
  • @YiyiYou What do I have to put into the action if I want to redirect to another page? Can I put the path in there? Maybe that's where I made the mistake. – bogii Nov 02 '22 at 11:00

0 Answers0