简体   繁体   中英

Javascript Multistep Form with Validation

I am trying to create a multistep form using javascript and div. I know how to create the form this way but the problem is I want the fields in each step to be validated before moving to the next. Example: If the user did not fill up a required field or have error in a field the box will be highlighted in red and they will not be bring to the next step until it is corrected. I know how to do validation but not able to stop the page. Any help will be appreciated.

Thanks!

To stop the form from submitting you need to add

<form id="form" onsubmit="validate(); return false;">

Validate is your function for validationg, then you can call something like this

document.getElementById('form').submit()

if the form is valid ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM