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'
}
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top