bill maxfith bill maxfith - 2 months ago 12
HTML Question

how to submit for after all the field are filled in javascript

basically i have a html form that contains a textbox and a submit button, what i want is when i pressed submit button it should check for the textbox that it have no error then proceed with submittion.

here is my button code:

<form id="thisform">
<div id="Registeration" class="Registeration">
<input type="text" id="textbox" class="textbox"
placeholder="My textbox" name="fBox" maxlength="30"/>

<div class="Registration_Submit_Div">
<input type="submit" value="submitform" id="SumbitForm_btn" class="SumbitForm_btn" name="Submit_btn" onclick="submit()"/>

return false;


Here's a plain JS example where the form is only submitted if the text is at least 5 characters long.

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">

  <form method="POST" action="result.html" class="da-form">
    <input type="text" name="textbox" class="textbox">
    <input type="submit" class="submit">


    var formEl = document.querySelector('.da-form');
    var submitBtn = document.querySelector('.da-form .submit');
    var textEl = document.querySelector('.textbox');

    submitBtn.addEventListener('click', function(event) {
      if (textEl.value.length >= 5) {
      } else {
        console.error('text should be at least 5 chars long');