How check checkbox is checked or not in php codeigniter?

CodeIgniter Checkbox Helper

Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's value does not get sent in the form values. Instead of telling CodeIgniter you want to set this value to 0, it says "don't change it." This fixes that, one by one, by setting the value of the associated $_POST array item to zero. You can also pass in an array of checkbox names and it will do each one.

Usage

$this->load->helper('checkbox');

// set post values to zero for unchecked boxes
fix_unchecked(['is_active', 'is_enabled', 'is_verified']);

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @author Mike Funk
* @link http://mikefunk.com
* @email
* @file checkbox.php
*/
/**
* checkbox value fixer. If a checkbox is not checked, sets it's value
* to zero.
* @param mixed $name the checkbox form field name. Can be passed as a
* string or as an array.
* @return void
*/
function fix_unchecked($name)
{
if (!is_array($name)) {$name = array($name);}
foreach ($name as $item)
{
if (!$this->input->post($item)) {$_POST[$item] = 0;}
}
}
/* End of file checkbox.php */
/* Location: ./application/helpers/checkbox.php */

September 6, 2020 Category : jQuery

Hi Dev,

Here, i will show you how to works jquery check if checkbox is checked or not. you can see how to check checkbox is checked or not in jquery on button click. Here you will learn jquery get checkbox value if checked.

if you have question about how to check checkbox is checked or not in jquery using id then i will give simple example with solution. You just need to some step to done jquery check if checkbox is checked or not.

We will use jquery prop() method to check checkbox is checked or not. So you can see bellow simple full example that will help you to understand example.

Solution:

$('input[type="checkbox"]').click(function(){

if($(this).prop("checked") == true){

alert("you checked checkbox.");

}else if($(this).prop("checked") == false){

alert("you unchecked checkbox.");

}

});

Example:

<!DOCTYPE html>

<html>

<head>

<title>jquery check if checkbox is checked or not - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h2>jquery check if checkbox is checked or not - itsolutionstuff.com</h2>

<label>

<input type="checkbox" name="i_agree"> I agree

</label>

<script>

$(document).ready(function(){

$('input[type="checkbox"]').click(function(){

if($(this).prop("checked") == true){

alert("you checked checkbox.");

}else if($(this).prop("checked") == false){

alert("you unchecked checkbox.");

}

});

});

</script>

</body>

</html>

I hope it can help you...

How check checkbox is checked or not in php codeigniter?

Hardik Savani

I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.

Follow Me:

We are Recommending you

  • How to set multiple selected value in Chosen Jquery Plugin?
  • Jquery modal dialog prompt using bootstrap bootbox JS example
  • How to check file size when select multiple file validation using Jquery?
  • How to set scroll to bottom in jquery?
  • Select only one checkbox at a time using Jquery
  • How to convert line breaks to br in jQuery ?
  • How to check Object is empty or not in Jquery/JavaScript ?

How check checkbox is checked or not in php codeigniter?

Popular Posts

  • Moment JS Get Month Name from Date Example
  • How to Get Checked Radio Button Value by Name in Jquery?
  • How to add custom jquery validation for image file upload in summernote ?
  • Jquery Remove Parent Table Row on Button Click Event
  • How to change view mode in bootstrap datepicker like yyyy-mm?
  • How to create responsive menu in html/PHP ?
  • Jquery Redirect to Another Page After 5 Seconds Example
  • PHP and MySQL - Login with Google Account Example
  • Moment JS Get Last Date of Month Example
  • Codeigniter multiple drag and drop image upload example from scratch
  • PHP - Bootstrap autocomplete tokenfield with Ajax Example

Categories

  • Laravel
  • Angular
  • PHP
  • jQuery
  • Python
  • Bootstrap
  • Javascript
  • MySql
  • Ajax
  • Node JS
  • HTML
  • Ubuntu
  • Codeigniter
  • Guest Post
  • Vue.JS
  • React JS
  • Git
  • Server
  • JSON
  • Installation
  • CSS
  • Google Map
  • SQL
  • .htaccess
  • Google API
  • JQuery UI
  • Typeahead JS
  • Axios
  • Socket.io
  • Elasticsearch

Latest Posts

  • Laravel Mail Send with PDF Attachment Example
  • How to set CC And BCC Email Address In Laravel Mail?
  • How to Check Running Laravel App Environment?
  • How to Check If Request Has File in Laravel?
  • Laravel Blade Check if Array Key Exists Example