Forums

Checkbox - Disable and change selected value

msreyes 21 Jul, 2020
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.
Max_admin 22 Jul, 2020
Answer
1 Likes
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!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Elita 31 Aug, 2021
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;
?>
spiceagent11 08 Sep, 2021
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.
This topic is locked and no more replies can be posted.