Select Multiple value from select box with check box | Sanwebcorner

Select Multiple value from select box with check box

This is another important concept to select the multiple value from one select box with the help of check box using jquery. Commonly we will select one value from the <select> box , It shows only option values from the select box like a dropdown list.  Some times we need to get multiple value from the select box so that kind of  places we need to use Jquery and css concept. Here is the solution to get more then one value from the select box

.

Here there are few jquery function used to set custom selectbox like toggle(), hide(), show(). To Set option box for each option in the select box. Each options captured its value ans stored using php  function implode(); This example contains full code and demo pages for your reference. This is very useful to select multiple value from the select box. Please check the demo page for live demo of this project.



Code for multiple select from selectbox:

<html>
<head>
<title>Select Multiple value from select box with check box</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="multiple-select-container">
<form id="fromCustomSelect" name="fromCustomSelect" action=""
method="post">
<div>
<?php
if(!empty($_POST["subjects"])) {
$selectedValues = implode(", ", $_POST["subjects"]);
?>
<div class="result-list">
<div class="result-list-heading">The Selected subjects: </div>
<div><?php echo $selectedValues; ?></div>
</div>
<?php
}
?>
<div class="multiple-select" id="multiple-select">Select Your Subjects</div>
<div id="multiple-select-option-box">
<div class="multiple-select-option">
<input onchange="toggleFillColor(this);"
class="multiple-select-option-checkbox" type="checkbox"
name="subjects[]" value="Tamil"> Tamil
</div>
<div class="multiple-select-option">
<input onchange="toggleFillColor(this);"
class="multiple-select-option-checkbox" type="checkbox"
name="subjects[]" value="English"> English
</div>
<div class="multiple-select-option">
<input onchange="toggleFillColor(this);"
class="multiple-select-option-checkbox" type="checkbox"
name="subjects[]" value="Maths"> Maths
</div>
<div class="multiple-select-option">
<input onchange="toggleFillColor(this);"
class="multiple-select-option-checkbox" type="checkbox"
name="subjects[]" value="Science"> Science
</div>
</div>
</div>
<button type="submit" class="search btn">Submit</button>
</form>
<br/><br/>
<h2 style="text-align:right; color:#fff;"><a style="text-align:right; color:#fff;" href="http://www.sanwebcorner.com">www.sanwebcorner.com</a></h2>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$("#multiple-select").on("click",function(){
$("#multiple-select-option-box").toggle();
});
function toggleFillColor(obj) {
$("#multiple-select-option-box").show();
if($(obj).prop('checked') == true) {
$(obj).parent().css("background",'#c6e7ed');
} else {
$(obj).parent().css("background",'#FFF');
}
}
$(".multiple-select-option").on("click", function() {
var checkboxObj = $(this).children("input");
$(checkboxObj).prop("checked",true);
toggleFillColor(checkboxObj);
});

$("body").on("click",function(e){
if(e.target.id != "multiple-select" && $(e.target).attr("class") != "multiple-select-option") {
$("#multiple-select-option-box").hide();
}
});
</script>
</body>
</html>

Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form multi-select-checkbox Multi-Step-form Multiple File Upload in PHP mysql News ticker on hover change text to image our team page password generator password strength checker Photoshop PHP php mailer populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips whatsapp link website Youtube