Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

multiple checkbox validation in jquery

function onSubmit() 
{ 
    var fields = $("input[name='list']").serializeArray(); 
    if (fields.length === 0) 
    { 
        alert('nothing selected'); 
        // cancel submit
        return false;
    } 
    else 
    { 
        alert(fields.length + " items selected"); 
    }
}

// register event on form, not submit button
$('#subscribeForm').submit(onSubmit)

//**************************************************
// HTML
<form method="POST" id="subscribeForm">
    <fieldset id="cbgroup">
        <div><input name="list" id="list0" type="checkbox"  value="newsletter0" >zero</div>
        <div><input name="list" id="list1" type="checkbox"  value="newsletter1" >one</div>
        <div><input name="list" id="list2" type="checkbox"  value="newsletter2" >two</div>
    </fieldset>
    <input name="submit" type="submit"  value="submit">
</form>
Comment

multiple checkbox jquery

//This are the list of checkbox(2 selected, 2 unselected)
<input name="numchec"  type="checkbox" value="1" checked/>
  <input name="numchec"  type="checkbox" value="2" />
  <input name="numchec"  type="checkbox" value="3" checked/>
  <input name="numchec"  type="checkbox" value="4" />
  
 //Jquery Code
 
 $(document).ready(function(){
     var data=$('input[name=numchec]:checked').map(function(err, el) {
      			return $(el).val();
  			}).get();
     alert(data)
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongoose connect 
Javascript :: javascript style inline react 
Javascript :: how to clone an object 
Javascript :: delete row in html table using javascript 
Javascript :: jQuery hello world program 
Javascript :: js numbers only string 
Javascript :: node qrcode 
Javascript :: js get fibonacci number 
Javascript :: javascript find the second highest Element from array 
Javascript :: await is only valid in async function 
Javascript :: get methods on an js object 
Javascript :: jquery ui dialog position fixed center 
Javascript :: magento 2 translate js 
Javascript :: for of loop 
Javascript :: how to delete a message by its id discord.js 
Javascript :: how to make unclicable legend chartjs 
Javascript :: is digit javascript 
Javascript :: moment set time 
Javascript :: javascript allow default 
Javascript :: javascript Strict Mode in Function 
Javascript :: document fragment 
Javascript :: js get all arguments from function 
Javascript :: execcommand javascript 
Javascript :: Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project. 
Javascript :: reverse array js 
Javascript :: javascript variable 
Javascript :: falsy values in javascript 
Javascript :: javascript console.table 
Javascript :: generate express app 
Javascript :: vue 3 hooks 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =