disable submit while correct forms not filled js

192
January 07, 2021, at 8:30 PM

i have issue with disable submit while corrects forms not filled. My code working, but need do some changes and idk how to solve it. My js

$(document).ready(function (){
    validate();
    $('#InputEventDate, #InputEventText').change(validate);
});
function validate(){
    if ($('#InputEventDate').val().length   >   0   &&
        $('#InputEventText').val().length    >   0) {
        $("input[type=submit]").prop("disabled", false);
    }
    else {
        $("input[type=submit]").prop("disabled", true);
    }
}

So i have form, in what form event time input and event text are necessary. So i disabled button and checking with what js length. Problem is they not check real time, need click something then my button becomes not disabled. I try change js like this.

$('#InputEventText').val($(this).val().length)   >   0 

But then i chose data, write idk why 10 in my event form and do nothing, submit not change to not disabled. Any idea how to solve it ?

Answer 1

when your validation process done you can send data using javascript

xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    // response -> this.responseText;
  }
};
xhttp.open("POST", "URL", true);
xhttp.send(Data);

OR

use onsubmit event in your form tag. do validation in that event.

<form onsubmit="return validate()">
Answer 2

If you're using vanilla javascript, you'll need to do a few things.

  1. Set state for each input. It depends on how many inputs you have. For example, isNameValid = false;
  2. Create an on change event listener and attach it to all inputs you want to track. Inside the event listener you need to validate the input, mark the input as valid and run a function that checks whether all input states are true. If all states are true, enable the button, otherwise disable it.
Rent Charter Buses Company
READ ALSO
pino-stackdriver only prints the word &ldquo;logging&rdquo;

pino-stackdriver only prints the word “logging”

I am trying to leverage the pino-stackdriver library to get proper log levels in stackdriver, but I just see the word "logging" printed to the console and that's it

186
not being asked to set password for mysql installation

not being asked to set password for mysql installation

I downloaded the mysql installer and installed it as neededHowever, i am not getting the option to configure the password

183
How to display apexChart donut type data using javascript in laravel?

How to display apexChart donut type data using javascript in laravel?

I am using Laravel 8 and Apex Chart library to display donuts chartI have data as,

197
Using parent class to contain many instances of child class

Using parent class to contain many instances of child class

I am trying to write a data processing script and I think I'm misinterpreting the structure of Object Oriented Programming in Python

168