-1

i am trying to display images in slideshow. in that i am using array of image paths.but the array is taking only firstvalue(firstimage) my javascript is

var res;
var sp = new Array();
var hdnvalue = a = document.getElementById('HiddenField4').value;
var imgArr = hdnvalue.split(';');
for (var count = 0; count < imgArr.length; count++) {
    if (count == 0) 
        res = '[' + imgArr[count];
    else if (count != imgArr.length - 1) 
        res += '","","",""],[' + imgArr[count];
    else 
        res += '","","",""],[' + imgArr[count] + '","","",""]';
}
sp = res.split(';');
alert(sp);

var mygallery2 = new fadeSlideShow({
    wrapperid: "fadeshow2",
    dimensions: [568, 313],
    imagearray: [ * * sp * * ],
    //<--array of images!],
    displaymode: {
        type: 'auto',
        pause: 2500,
        cycles: 0,
        wraparound: false
    },
    persist: false,
    //remember last viewed slide and recall within same session?
    fadeduration: 500,
    //transition duration (milliseconds)
    descreveal: "always",
    togglerid: "fadeshow2toggler"
})

where sp is an array where i am storing imagepaths. is this the correct way to assign an array like
imagearray: [ sp ],

1
  • Whats with the res var? You want to set var sp (array) so you can pass it to fadeSlideShow() as imagearray, right? What’s the desired format of that array you want to pass then? Really, what you’re doing there with strings is not what you want to do unless you HAVE to pass it as a string. Instead manipulate arrays themselves. imgArr is the source array? Can’t you just use that? Please provide the source array format and desired array format, so we know what you want to convert from and what to. Commented Nov 10, 2010 at 15:02

3 Answers 3

1

You are storing an array in the first index of an array.

If you want to store the array, than reference it

imagearray: sp,
Sign up to request clarification or add additional context in comments.

Comments

0

Just use:

    // ...
    imagearray: sp,
    // ...

You've already built an array, so just refer to its name.

Comments

0

(This is not really an answer but a comment, but I need to write longer)

It's quite confusing what you are doing there.

You seem to creating a string in the variable res. What's the idea there? What are you exactly trying to achieve in the loop?

Then you split that string at semicolons (sp = res.split(';');), but that string can't contain any semicolons.

can it be you need to create an array of arrays where the inner arrays contain of one non-empty string and three empty strings? In that case you probably want something like this:

var imgArr = hdnvalue.split(';');
var sp = [];
for (var count = 0; count < imgArr.length; count++) {
   sp.push([imgArr[count], "", "", ""]);
}

var mygallery2 = new fadeSlideShow({
    wrapperid: "fadeshow2",
    dimensions: [568, 313],
    imagearray: sp, 
 /* ... etc. ... */

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.