Robus Robus - 1 year ago 73
jQuery Question

When does the jquery change function trigger?

Referring to this post: Jquery execute onchange event on onload

I got the opposite Problem.

This was my first attempt but the function executes on page load

I excpected it to trigger on the first change.

function get_items(){

This one works and there is only an alert if i really change the select_field:


It is probably some basic stuff but i cant find anything helpfull.
Can someone pls explain whats happening here?

Thank you

Answer Source

$('#select_field').change(get_items()); should be $('#select_field').change(get_items);

Binding event handlers requires passing a function reference. When you call get_items() you're executing the function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download