newbie
newbie

Reputation: 14960

Passing objects in javascript

I want to pass an object in javascript. But i am getting an error javascript:callbackCredits(1,dotsContainer_credits); is undefined

My code is as follows:

var dotSlideCredits = {
    show : 3,                       
    width : 430,  
    functionName : "callbackCredits",       
    title: "title",
    itemId: "#s_credit"
}

var test = {
     data[]
}

$(document).ready(function(){
   dynamicList(dotSlideCredits);
}

 function dynamicList(dotSlide){
            var divItems = "dotsContainer_"+dotSlide.title;
        test.data.push({title: dotSlide.title+[i], callBack:  "javascript:"+dotSlide.functionName+"("+i+","+divItems+");"});
 }


 function callbackCredits(current, container){
    var prev = $("#previousCredit").val();
    slideShow(current, prev, container);       
    $("#previousCredit").attr("value", current);
 }

Upvotes: 2

Views: 136

Answers (3)

Álvaro González
Álvaro González

Reputation: 146630

I think the error message is pretty descriptive. You've added a bogus "javascript:" prefix to your function name. Remove it.

Upvotes: 0

NakedLuchador
NakedLuchador

Reputation: 991

what i would do probably is something like that :

var dotSlideCredits = { 
    show : 3,                        
    width : 430,                         
    itemId: "#s_credit",
    functionName: function(current, container){
      callbackCredits(current,container);
    }
} 

function callbackCredits(current, container) { var prev = $("#previousCredit").val();
slideShow(current, prev, container);
$("#previousCredit").attr("value", current); }

and then simply call dotSlide.functionName(i,divItems);

(not tested bout should be something close to that)

Upvotes: 1

paulslater19
paulslater19

Reputation: 5917

Are you sure the callBack property isn't a function? It probably should be

E.g.:

test.data.push({
    title: dotSlide.title+[i], 
    callBack: function () {
        dotSlide.functionName(i,divItems);
    }
});

does that make sense?

Upvotes: 1

Related Questions