0

I'm developing a web app in grails and I have my gsp, and my .js file, I want to check if when I change a value of my combobox I can access to the function, but nothing happens... these are my codes:

javascript [dynamic.js]:

function cmbFilters(){
alert("Hello");
}

GSP [numberJobs.gsp]:

<a>Filter by :</a> <g:select id="cmbFilterBy" name="cmbFilterBy"  
 onchange="cmbFilters()" from="${['None','Name', 'Owner', 'Description', 'Status', 
'Cron   Expression']}"></g:select>

and in my Application Resources.groovy i have this:

numberJobs{
    resource url:'css/custom.css'
    resource url:'js/dynamic.js'
}

1 Answer 1

3

g:select doesn't accept an onchange attribute, and the g:select tag will be replaced by HTML.

If you view source on the page you should not see the onchange set on the real html select.

What you can do is attach a listener to the change event for that select.

Example using jQuery

$('#cmbFilterBy').on( "change", function(){ cmbFilters() } );

Here is a simple fiddle.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, it doesn't recognize it, but that jquery code dodn't work neither!
I just make an alert("Hi"); inside the function cmbFilters after created the listener and nothing happens
I updated the answer with a fiddle you can mess with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.