Buy Now
Sign in

Checkbox - Disable and change selected value

msreyes , July 21 2020, 19:36
M
msreyes 57
July 21 2020, 19:36 #393410
I have a checkbox that 90% of the time user will just select either YES or NO.  Always enabled.
But when I retrieve a record under certain criteria I want to ensure the checkbox is selected with the NO option and DISABLED so user cannot change it.
I have the IF condition working, just don't know the syntax on how to get this to go to NO, and then disable the checkbox.
admin 33
July 22 2020, 02:26 #393414
 1
 Answer
use php:
$this->set("checkbox_disabled", false);
if(condition){
$this->data["checkbox_name"] = 0;
$this->set("checkbox_disabled", true);
}
then add {var:checkbox_disabled} in the disabled field in the checkbox settings!
M
msreyes 57
July 22 2020, 17:43 #393421
 1
I love code
E
Elitakey 370
August 31 2021, 17:50 #397018
Thanks Max, code is usable, however, I can get only checkbox disabled, bu cannot get it enabled. How that should be done? The code below not working.
obviously $this->set("checkbox_disabled", false); is not the right code
<?php

$klatiene= $this->data['klatiene'];
$klatiene_skaits=20;
$skaits=$this->data['skaits'];


// Izrekina atlikušo skaitu
$klatiene_atlikums=$klatiene_skaits-$klatiene;


// paziņojums
$this->set("checkbox_disabled", false);
if($klatiene_atlikums< $skaits) {
echo "Vietu skaits klātienē ir beidzies!";
$this->data["checkbox_name"] = 1;
$this->set("checkbox_disabled", true);
} else{
echo "<p>Atlikušais vietu skaits klātienē: " . $klatiene_atlikums . " vietas</p>";
$this->data["checkbox_name"] = 1;
$this->set("checkbox_disabled", false);
}

$this->data['klatiene_atlikums']=$klatiene_atlikums;
?>
S
spiceagent11 1
September 08 2021, 16:07 #397054
But when I retrieve a record under certain criteria I want to ensure the checkbox is selected with the NO option and DISABLED so user cannot change it.