Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if input is empty

<!-- check if any input field in "Form" is empty using JS -->

<script type="text/javascript">
  function validateForm() {
    var a = document.forms["Form"]["answer_a"].value;
    var b = document.forms["Form"]["answer_b"].value;
    if (!a || !b) {
      alert("Please Fill All Required Fields");
      return false;
    }
  }
</script>

<form method="post" name="Form" onsubmit="return validateForm()" action="">
  <input type="text" name="answer_a" value="">
  <input type="password" name="answer_b" value="password">
</form>
Comment

PREVIOUS NEXT
Code Example
Javascript :: aboutreact axios 
Javascript :: javascript convert string to number with 2 decimal places 
Javascript :: Check If Key Exists For Object 
Javascript :: react extends component with style 
Javascript :: removing the first match in array 
Javascript :: nodejs express parse query params boolean 
Javascript :: Constructor can also be written like this 
Javascript :: [jQuery] Moving elements in dom 
Javascript :: string inverter vs property binding in angular 
Javascript :: Backbone Model Set Can Set Muliple Values At Once 
Javascript :: Changing Prototype 
Javascript :: Can Execute Backbone In RequireJS 
Javascript :: select 2 is not working in nodejs 
Javascript :: save slug on schema pre save in node js 
Javascript :: Scale to fit 
Javascript :: $() in javascript 
Javascript :: nextjs youtube embed 
Javascript :: multi command run in one in terminal npm 
Javascript :: vite displays blank page in docker container 
Javascript :: jquery find include self 
Javascript :: $Javascript $.get( 
Javascript :: javascript detect if active element is writable 
Javascript :: ArrayReplace 
Javascript :: how to convert javascript to typescript angular 
Javascript :: how to check my javascript code 
Javascript :: scriptcase transforming local to global variable 
Javascript :: (state.isLoggedIn = function() {return false}) react redux 
Javascript :: laravel onkeyup textbox, get value from span javascript 
Javascript :: getting xml from response, make sure server returns valid xml and the "content-type" header is set 
Javascript :: angularjs Split date and time from api response 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =