Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-28-2012, 06:09 AM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Using the Change feature in jQuery with Chosen

All,
I'm using the Chosen plugin (http://harvesthq.github.com/chosen/). It says that I can use the following for any change events:

Form Field Change
When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event* on the original form field. That let's you do something like this:
Code:
$("#form_field").chosen().change( … );
Note: Prototype doesn't offer support for triggering standard browser events. Event.simulate is required to trigger the change event when using the Prototype version.

However, when I do this in my code and try and do something like this:
Code:
$("#form_field").chosen().change( alert("this is an alert"); );
Or Something like this:
Code:
$("#form_field").chosen().change({ alert("this is an alert"); });
It never gives me an alert and actually makes the rest of my jQuery not work. Can anyone figure out how to use this change feature? Any advice is appreciated!

Thanks!
treeleaf20 is offline   Reply With Quote
Old 02-28-2012, 07:38 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
The first parameter of the .change() method has to be a function reference rather than a call to a function.
Code:
$("#form_field").chosen().change( function() {alert("this is an alert"); });
devnull69 is offline   Reply With Quote
Old 02-28-2012, 04:34 PM   PM User | #3
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Thanks, that worked great. However I do have another question. Does Chosen pass an action with the change? For example, it calls the change event but I only want something to happen if I clicked the remove button. Is there any way to determine that action in this function?

Thanks!
treeleaf20 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:24 PM.


Advertisement
Log in to turn off these ads.