Re: SOLVED: QuickForm: Event on Element to change other elements
| From: | Marco Schuler | Date: | Wed, 09 Jun 2004 14:15:12 +0000 |
| Subject: | Re: SOLVED: QuickForm: Event on Element to change other elements | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13038@lists.php.net to get a copy of this message | ||
Hi
Am Mi, 2004-06-09 um 12.34 schrieb Bertrand Mansion:
> Marco Schuler wrote:
>
> >Hi
> >
> >I have a form with some selct-boxes. What I want is tte following: the
> >user should only be alloewd to select from one select-box. So if for
> >example some items in a particular select-box are selected, they should
> >be unselected when the user selects items from another select-box. Is
> >there a way to do that in QuickForm or do I need to engage some
> >javascript therefore?
> >
> >Any hints and tips are appreciated!
>
> You will have to write some javascript I am afraid and set a javascript event
> on your selects.
The following javascript-code performs my desired task:
<script type="text/javascript">
<!--
function unselectOtherSelectboxes(theForm, focusedSelectBox)
{
var allFormElements = theForm.elements;
for (i = 0; i < allFormElements.length; i++) {
if ( (allFormElements[i].type == "select-multiple") ||
(allFormElements[i].type == "select-one")) {
if (focusedSelectBox != allFormElements[i]) {
allFormElements[i].selectedIndex = -1;
}
}
}
}
//-->
</script>
Then use the code below to build up your form:
$attr = array('onchange' => "unselectOtherSelectboxes(this.form,
this)");
$this->addeElement('select', 'sel_id', null, $opts, $attr);
--
Regards
Marco