checkbox problem

admin_wiky 30 Sep, 2015
Hi all,

I have a problem with checkbox .. .I dont know how set value to checked by value from db - $form->data['faktury']['autorizovano']
anyone knows?

thank you
admin_wiky 30 Sep, 2015
I will be more specific.
I have value (user number) in row AUTORIZOVANO in db and I need to set checkbox to checked/unchecked depending on value from db.
I did try something like that
if (isset($form->data['faktury']['autorizovano']))
  {
    $form->data['faktury']['temp']=$form->data['faktury']['autorizovano']; // move value to temp var for next use
    $form->data['faktury']['autorizovano']=1;  // set ckeckbox as checked
  }

but checkbox didnt checked and I think that is wrong.
GreyHead 30 Sep, 2015
Hi Homeopat,

What is the value of the Checkbox?

Bob
admin_wiky 01 Oct, 2015
Hi Bob,
I wrote it, value in db is integer - user number from joomla.
I want to: if checkbox is checked (authorized), then set number of logged user to row AUTORIZOVANO.
problem is that I cant affect checkbox to check or uncheck in code.
GreyHead 01 Oct, 2015
Hi homeopat,

A checkbox can't have a variable number as a value. I don't understand what you are trying to do here.

Bob
admin_wiky 02 Oct, 2015
Hi Bob,
when is checkbox marked (1) then userID must be put to AUTORIZOVANO row in db.
when I open existing record and AUTORIZOVANO row has value > 0 then checkbox must be marked (1).

do u understand now?
thank you
GreyHead 02 Oct, 2015
Hi homeopat,

You have to do this with Custom Code actions:

In the form ON Submit before the DB Save action
<?php
$temp = '';
if ( !empty($form->data['checkbox_name']) && $form->data['checkbox_name'] == 1 ) {
  $user = \JFactory::getUser();
  $temp = $user->id; 
}
$form->data['AUTORIZOVANO '] = $temp;
?>

and in the On Load event after the DB Read and before the HTML (render form) action
<?php
$temp = '';
if ( $form->data['AUTORIZOVANO '] > 0 ) {
  $temp = 1;
}
$form->data['checkbox_name'] = $temp;
?>
I'm not clear what the actual element names are so you'll need to edit those.

Bob
admin_wiky 05 Oct, 2015
Hi Bob,

I have had set something like that in code ..... but checkbox is not set after modification of code.
I think that problem is that checkbox dont work with value but with word checked in element.
I see in debugger that checkobox has value = 1 but didnt checked.
admin_wiky 22 Oct, 2015
Hi Bob,
I found out this JS code for dynamic checkboxes with dropdown.
I implemented it to my CF, but it doesnt work.

could u take a look and tell my if is any problem with this JS and Chronoengine?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/JavaScript">
var dances = new Array()
dances[0] ='Joy Of Dance';
dances[1] ='Jazz';
dances[2] ='Tap';
dances[3] ='Modern';
dances[4] ='Ballet';
dances[5] ='Musical Comedy';
dances[6] ='HipHop';
function picked(s){
if(s==0){removeC()}
else if(s<3){createC('0')}
else if(s<5){createC('124')}
else{createC('123456')}
}
function createC(p){
removeC();
var p = p.split('');
var root = document.getElementById('che');
for(var i=0;i<p.length;i++){
var t = dances[Number(p[i])];
var oInp = document.createElement('input');
var oTxt = document.createTextNode(t);
var oBr = document.createElement('br');
oInp.setAttribute('type','checkbox');
oInp.setAttribute('name',t);
oInp.setAttribute('value',t);
root.appendChild(oInp);
root.appendChild(oTxt);
root.appendChild(oBr);
}
}
function removeC(){
var root = document.getElementById('che');
while(root.hasChildNodes()){
root.removeChild(root.childNodes[0])
}
}
onload = function(){
document.getElementsByName('age')[0].selectedIndex=0;
}
</script>
</head>
<body>
<select name="age" onchange="picked(this.selectedIndex)">
<option selected>Choose</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="adult">20 and up</option>
</select>
<div id="che"></div>
</body>
</html>  


thank you
admin_wiky 22 Oct, 2015
previous modification works, sorry.
This topic is locked and no more replies can be posted.