tags:

views:

43

answers:

2

Good afternoon.

I have a little problem with triggering the change of a select box in jQuery.

I have juts built a plugin that takes a select box with it's options and turns it into an iPhone style (what I call) roller - basically a fixed height element with an up and down arrow on the right that makes the list in the box go up and down.

I have all this working correctly and the corresponding select element setting the correct selectedIndex and it's all peachy.

The one trouble I have is that I need to trigger a change when the selectedIndex changes. At first I just hid the select element hoping that I could trigger it with it hidden - but this doesn't work, then I just made the z-index -100 again hoping it would work but to no avail. Does the select element have to be visible for the change to take place or is there another way I can get round it. I would like it to be chainable in true jQuery spirit but that no worky either.

Kind regards

Alex

A: 

Can you show some of your code or markup? The element shouldn't have to be visible in order to trigger a change event. I assume you've tried a simple $('#my-select').change()? For example:

$('#my-select').change(function() {
  alert('changed');
}).change();​​​​

Here's a live demo that registers and triggers a change event on a hidden select box: http://jsbin.com/okeqo3/2/edit

jmar777
http://pastie.org/1099796Excuse the code - it's rushed to see if it would work - I do plan to tidy it up and use less memory!!!!
Alex
A: 

It's okay, I found a work around for it - adjusted some code and it's all good.

Thanks for the help peoples

Alex