Hi,
There''s nothing out of the box in Prototype or Scriptaculous that will
implement this behaviour, but Prototype''s various helper functions can
make
it smoother to hand-code it. Basically, you want to set an onchange callback
function on each <select> element that will disable the other list unless
it
has just had the empty value selected, in which case it enables it.
So, let''s say they have id attributes sel1 and sel2, and the empty
option has
a value of ''null'', i.e.
<select id=''sel1''>
<option value=''null''>please select...</option>:
<option value=''blah''>etc.</option>
...
</select>
Add a bit of behaviour as follows:
Event.observe("sel1","change", function(){
var selected=$F("sel1"); //read own current value
if (selected=="null"){
$(''sel1'').disabled=true;
$(''sel2'').disabled=false;
}else{
$(''sel1'').disabled=false;
$(''sel2'').disabled=true;
}
});
and similarly for the sel2 element.
That technically accomplishes what you''ve described, I think. However,
if you
don''t mind me saying, it''s a curious kind of UI
you''re describing. If you
want the two lists of options to be mutually exclusive, why not put them all
in one drop-down list, possibly with subheads to ensure that they''re
seen as
two distinct groups if appropriate?
As implemented above, there''s an awkward bit of workflow around them
automatically disabling themselves. Say I accidentally select the empty
option on sel1. I then need to select empty on sel2 in order to re-enable
sel1 and pick the option I really wanted. Could be confusing to mis-select an
element and then see the list go grey on you? Would the untrained user know
to go twiddle sel2 in order to make sel1 work again?
HTH
Dave
----------------------
Author
Ajax in Action http://manning.com/crane
Ajax in Practice http://manning.com/crane2
Prototype & Scriptaculous in Action http://manning.com/crane3
On Thursday 22 March 2007 18:54, ssk wrote:> I''m using Eclipse to build a JSP page that has a netui:form on it.
> this form has two dropdown lists. I need a JavaScript function that
> will allow for a user to select a value from dropdown1 (change away
> from the default null) and then dropdown2 will be disabled, and vice-
> versa. in other words, this form can only be submitted when one and
> only one of the dropdown lists has a non-null value selected. can
> anyone help with this? i have the prototype library available to me as
> well.
>
>
> >
>
> --
> This email has been verified as Virus free
> Virus Protection and more available at http://www.plus.net
--
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---