diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 9f547c0b..a1866ffc 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -1286,6 +1286,8 @@ class htmlRadio extends htmlElement { private $selectedElement = null; /** enabled or disabled */ private $isEnabled = true; + /** on change code */ + private $onchangeEvent = null; /** * Constructor. @@ -1326,16 +1328,27 @@ class htmlRadio extends htmlElement { if (!$this->isEnabled) { $disabled = ' disabled'; } + $onchange = ''; + if ($this->onchangeEvent != null) { + $onchange = ' onchange="' . $this->onchangeEvent . '"'; + } // print radio list $counter = 0; foreach ($this->elements as $label => $value) { - $onClick = 'onClick="jQuery(\'input[name=' . $this->name . ']\').attr(\'checked\', false);jQuery(\'#' . $this->name . $counter . '\').attr(\'checked\', true);"'; + $onClick = 'onClick=" + jQuery(\'input[name=' . $this->name . ']\').attr(\'checked\', false); + jQuery(\'#' . $this->name . $counter . '\').attr(\'checked\', true); + jQuery(\'#' . $this->name . $counter . '\').trigger(\'change\'); + "'; + if ($this->isEnabled === false) { + $onClick = ''; + } echo '
'; $selected = ''; if ($value == $this->selectedElement) { $selected = ' checked'; } - echo ' ' . $label; + echo ' ' . $label; echo '
'; $tabindex++; $counter++; @@ -1352,6 +1365,15 @@ class htmlRadio extends htmlElement { $this->isEnabled = $isEnabled; } + /** + * Sets the JavaScript code for the onchange event. + * + * @param String $onchangeEvent onchange event code (e.g. myfunction();) + */ + public function setOnchangeEvent($onchangeEvent) { + $this->onchangeEvent = htmlspecialchars($onchangeEvent); + } + } /**