Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

QuickForm and the DOM disabled Property

Can they work together?

6:35 pm on Jan 31, 2008 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2008
votes: 0

Hi! I'm totally illiterate when it comes to Javascript, and I'm stuck here with trying to use the DOM disabled Property to disable a select within a form generated with PEAR's HTML/Quickform.

Here is what I'm trying to achieve :

- When the page loads, a Javascript call to the DOM disabled Property disables a select menu identified by its ID (let's call it SELECT A).

- When another select menu (let's call it SELECT B) is modified, a Javascript function evaluates the value it returns. If some specific value is returned, it then uses the DOM disabled Property to set SELECT A to enable.

So far I've been able to get and display the value sent by SELECT B when modified, with the following code :

QuickForm code :

$form->addElement('select', 'selectb', 'SELECT B :', $selectb_options, array('onchange' => "check(this.options[this.selectedIndex].value)"));

Javascript code :

function check(the_value) { alert(the_value); }

My problem is I can't get Quickform to actually use Javascript to disable SELECT A when loading.

I have the following QuickForm code to generate SELECT A :

$form->addElement('select', 'selecta', 'SELECT A :', $selecta_options, array('id' => 'selecta'));

I have confirmed that the HTML generated is proper :

<select id="selecta" name="selecta">

and the select works fine.

But I'm unable to have it disabled, even with the following code in the page's headers :

<script language="javascript" type="text/javascript">

So, obviously, I'm stuck and can't go forward implementing all the nifty things that come after this (the condition upon the value returned by SELECT B and the call to either the enable() or disable() functions I intend to write).

Anybody would have an idea why this is not working? A simple select construct works fine with the DOM Disable, like here : [w3schools.com ] so I suspect QuickForm to be the problem here... Maybe an "onload" to the form's init? (how?)?

Thanks guys!

8:48 pm on Feb 1, 2008 (gmt 0)

New User

10+ Year Member

joined:Jan 6, 2008
votes: 0

Ok, just for the record, I found a workaround. I used QuickForm's "hierselect" statement and set it up so that the second select shows a "N/A" value except when the right selection is made within the first select. Then it shows the sub-values. Took a bit of array mingling on the backend, but that's working!