Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

multiple checkbox validation in javascript

// HTML 
/*
<div class="p-2">
<form onsubmit="return handleData()" method="post" action="https://postman-echo.com/post">
Select all the scripting languages you know:
<div style="visibility:hidden; color:red; " id="chk_option_error">
Please select at least one option.
</div>
<div>
<input type="checkbox" name="langs[]" id="langs_javascript" value="JavaScript" checked> <label for="langs_javascript">JavaScript</label>
</div>
<div>
<input type="checkbox" name="langs[]" id="langs_perl" value="Perl"> <label for="langs_perl">Perl</label>
</div>
<div>
<input type="checkbox" name="langs[]" id="langs_php" value="PHP" checked> <label for="langs_php">PHP</label>
</div>
<div>
<input type="checkbox" name="langs[]" id="langs_ruby" value="Ruby"> <label for="langs_ruby">Ruby</label>
</div>
<div>
<input type="submit" name="submit" value="Submit"/>
</div>
</form>
</div>
*/

// Javascript
function handleData()
{
    var form_data = new FormData(document.querySelector("form"));
    if(!form_data.has("langs[]"))
    {
        document.getElementById("chk_option_error").style.visibility = "visible";
      return false;      
    }
    else
    {
        document.getElementById("chk_option_error").style.visibility = "hidden";
      return true;
    }

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: json object array 
Javascript :: search array for property js 
Javascript :: modify array js 
Javascript :: hasChildNodes 
Javascript :: what is weakmap and weakset in javascript 
Javascript :: js while loop 
Javascript :: call,bind and apply in javascript 
Javascript :: date-fns 
Javascript :: change icon on click angular 
Javascript :: react return value from component 
Javascript :: how to use the foreach fnction javascript loop through array 
Javascript :: javascript reversing an array 
Javascript :: big o theory 
Javascript :: javascript cheat sheet 
Javascript :: javascript string literal 
Javascript :: object javascript 
Javascript :: module imports as default 
Javascript :: javascript url replace 
Javascript :: module 
Javascript :: .classList 
Javascript :: react navigation header title 
Javascript :: vue js skeleton loading 
Javascript :: difference between || and ?? in js 
Javascript :: json_extract in non native query 
Javascript :: how to compile typescript to javascript es6 
Javascript :: js embedded function 
Javascript :: template literals in js 
Javascript :: node js api with mongodb 
Javascript :: js chrome extension get current url 
Javascript :: function 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =