Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js form check all required input


document.getElementById("check").onclick = function() {
  let allAreFilled = true;
  document.getElementById("myForm").querySelectorAll("[required]").forEach(function(i) {
    if (!allAreFilled) return;
    if (!i.value) allAreFilled = false;
    if (i.type === "radio") {
      let radioValueCheck = false;
      document.getElementById("myForm").querySelectorAll(`[name=${i.name}]`).forEach(function(r) {
        if (r.checked) radioValueCheck = true;
      })
      allAreFilled = radioValueCheck;
    }
  })
  if (!allAreFilled) {
    alert('Fill all the fields');
  }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: $post in jquery 
Javascript :: custom event handler javascript 
Javascript :: redux devtools extention in redux toolkit 
Javascript :: angularjs download xml file 
Javascript :: datatable on page change 
Javascript :: js merge 2 lists 
Javascript :: jquery check checkbox 
Javascript :: populate dropdown using jquery from database 
Javascript :: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string. 
Javascript :: prevent default jquery 
Javascript :: MVC view pass model to javascript function 
Javascript :: which methods do not have the hook equivalents in reactjs 16.8++ 
Javascript :: javascript get value 
Javascript :: npm stylelint 
Javascript :: how to access key of object in javascript 
Javascript :: if back react 
Javascript :: debounce react 
Javascript :: latin science words 
Javascript :: How to get the input from a textbox javascript 
Javascript :: return more than 1 value from function js 
Javascript :: react native android padding style 
Javascript :: how to run bare react-native project 
Javascript :: javascript find all matches in array 
Javascript :: how to numbers by checked in checkbox in javascript 
Javascript :: javascript object to query params 
Javascript :: i18n react get current language 
Javascript :: how to get unique values from array in javascript without duplicate value 
Javascript :: render react in blaze 
Javascript :: crear proyecto angular 
Javascript :: typeorm config 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =