Lara
Lara

Reputation: 9

Checking g-select mapping properties

Hello I created this dropdownbox

  <g:select from="${[['key':1, 'value':'text1'],['key':2, 'value':'text2' else']]}" optionKey="key" optionValue="value" name="mine"/>

My question is how can I print the message "hi" everytime I have clicked on the text1 field

Upvotes: 0

Views: 38

Answers (1)

Mike B
Mike B

Reputation: 2784

For the select you can use attribute onchange to set the function it will call when value is changed:

<g:select onchange="printmsg(this)" from="${[['key':1, 'value':'text1']....

Then you write that function that checks the new value for the select and determines if it is what you are looking for.

printmsg = function(element) {
   var chosen = $(element).val();
   if (chosen === "text1"){
      alert("Omg. What have you done?!");
   }
}

Of course put Javascript in gsp page (and for this code add jquery library) as well.

Upvotes: 1

Related Questions