Welcome Guest, Not a member yet? Register   Sign In
check-box conditioning
#1

Hi coders,


i have list of check-box and there are same value and there are not. now i want to create condition, example if i check 3 check-box with different value it retrurn false, while if i check 3 checkbox with the same value it wil return true.


how do i in php? 


any help well appreciate . . . .


thanks
Reply
#2

(This post was last modified: 02-05-2015, 09:52 AM by egall8.)

(02-04-2015, 11:52 PM)jaysondotp Wrote: Hi coders,


i have list of check-box and there are same value and there are not. now i want to create condition, example if i check 3 check-box with different value it retrurn false, while if i check 3 checkbox with the same value it wil return true.


how do i in php? 


any help well appreciate . . . .


thanks

First you will have to post it somewhere so for example purposes we'll say the form/checkboxes is located at http://example.com/admin/form

We will say you are submitting the form to : http://example.com/admin/save
In the admin controllers --> save method you will have to get the data from the $_POST once you have that is when you can check if you have three values of the same like so:

PHP Code:
$i 0;
$vals =array();
foreach (
$data as $key => $value) {

if (!
in_array($value$vals)) {
$vals[] = $value;
}
else {
$i++;
}
}

if (
$i >= 3) {
return 
FALSE;
}
else {
return 
TRUE;


Or you could use jQuery to not even let it get to that point.

Code:
<script type="text/javascript">
$('#my_form').submit(function(e) {
e.preventDefault();

$('input['type="checkbox"]').each(function() {
// check each input here
});

});

</script>
Reply
#3

Thanks "egall8"..

and here is the scenario. take a look an image below as you reference. check-box value is PR No. which is, when i check different PR No. it will come false. else return true. how could i make it in php or in javascript....


[Image: Untitled_3.jpg]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB