0

I'm having some difficulty passing values and arrays between this two functions

Here's the code:

 $(document).ready(function(){
        ....
        ....    
    var srcImageFS =$('#imageAnimated').attr('src');    
    var array = []; 
    $('.myLightbox').each(function(i) {
         array.push($('.myLightbox').eq(i).attr('href'));
    });

    $('#rightArrowFS').click(function(array, srcImageFS ){
            alert(array +' || --> ' +srcImageFS );
            imageRight();

        });
...
...
});

and

function imageRight(array, srcImageFS ){
        $('#imageAnimated').fadeOut();
        $('#imageAnimated').src(array[i+1]);
        $('#imageAnimated').fadeIn();
        srcImageFS = $('#imageAnimated').src();
        arrowsState(array, srcImageFS );
}
3
  • 2
    What are you trying to pass and how? Commented Jul 21, 2011 at 16:05
  • what are you trying to pass? Is imagemAnimada same as imageAnimated ? i think you have a typo here Commented Jul 21, 2011 at 16:06
  • Just uppdate the code wit the correct names. Sorry about that. I'm trying to pass array and srcImageFS. I trid to imageRight( array, srcImageFS); but without success. The alert gives me [object Object] || --> undefined Commented Jul 21, 2011 at 16:12

2 Answers 2

1

In the example code, you don't actually try to pass anything to imageRight - the parameter list is empty. Also, you overwrite the value of srcImageFS inside imageRight before using it.

srcImageFS is undefined because jQuery couldn't find a src attribute on $('#imageAnimated') so your selector might be wrong, too.

imageRight(array, srcImageFS);

Will actually call the function with the arguments you want.

Sign up to request clarification or add additional context in comments.

2 Comments

yap you are right. thanks. on the second block of code I want to change the source of #imageAnimated. I tried $('#imageAnimated').src(array[i+1]); , but var i is not passed. Do you have any idea how can I do it??
.attr('src', array[i+1]) src is an attribute api.jquery.com/category/attributes
1

in the document.ready function where ur calling the imageRight() function u should instead call imageRight(array, srcImageFS ) ur nt passing any values to the function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.