0

I have a form with two selects, but the second select is optional depending on the value selected from the first. For instance:

<select name="country" from="['US', 'CA']">

<select name="language" from="['FR', 'EN']" disabled=true>

Only if CA was selected from country do I want language combobox active.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
Walt
  • 11
  • 2
  • 1
    You've tagged this `grails` and `gsp`, but I'd actually do this using Javascript - do a check of the first select and hide/unhide the second select as required. – Ciaran Archer Mar 01 '11 at 16:38
  • Looks like duplicate of http://stackoverflow.com/questions/3770765/grails-load-data-on-one-combobox-depending-on-another – Victor Sergienko Mar 02 '11 at 11:00

2 Answers2

2

Grails doesn't provide a way to do this by default. Since GSP tags allow you to use normal HTML events you would need to write JavaScript to enable and disable the second select based on the value of the first. You will want to look at the onchange event to do this. If you need to do a lot of custom UI type stuff you may want to look at using a JavaScript plugin for Grails. Prototype is included with Grails by default. Several other java script libraries are available as Grails plugins including jQuery and YUI

Jared
  • 39,513
  • 29
  • 110
  • 145
0

I agree, javascript is what you want. I'd recommend writing this in JQuery, since Grails is going to making that the default (over Prototype) in, I believe, v1.4. To do this in JQuery it would be something like this:

$("[name=country").change(function() {
  $("[name=language]").attr("disabled", ($(this).val() == "CA"));
});
Melv
  • 2,201
  • 16
  • 14