onChange function?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

onChange function?

havarti
When I add a parameter to the function I want to call from the onChange option, it is applied to the entire gallery directly after document loads and not after each shadowbox iteration. Is that the way it is suppose to work? I thought it would apply to each element in the gallery after the "next" button is selected.

What I get is 3 alert boxes (displaying the correct parameters) one after another as soon as the page loads but before the shadowbox window is ever initiated by a "click".

Is there any further documentation around or examples of how the onChange function is used?

Below is a simplified version of my code.

//javascript
$(document).ready(function(){
     Shadowbox.init();
});

function myFunction(myParam){
     alert(myParam);
}

//html
<a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:myFunction('1')}">image 1</a>
<a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:myFunction('2')}">image 2</a>
<a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:myFunction('3')}">image 3</a>

Reply | Threaded
Open this post in threaded view
|

Re: onChange function?

Wizzud
It's because what you have actually done is put in a call to a function, not a reference to a function (to be called at some later time).

You might get away with doing it this way (untested!) ...

//html
<-a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:function(obj){myFunction(1)}}">image 1
<-a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:function(obj){myFunction(2)}}">image 2
<-a href="image1.jpg" rel="shadowbox[myGallery];options={onChange:function(obj){myFunction(3)}}">image 3

I say might because you are extremely limited in what you can put into the onChange function when used this way, due to the way Shadowbox splits out the rel attribute to determine the properties (splits on semi-colon).
You would be better off simply declaring a generic onChange callback and getting the 1, 2 or 3 from the text of the link, say.
Combine literacy with curiosity and a whole world of information opens up to you
Reply | Threaded
Open this post in threaded view
|

Re: onChange function?

havarti
Thanks, I ended up declaring my own onChange callback.