2

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);
 }
10
  • 1
    looking at the code up there i cant find where you set dotSlide.functionName ... that could be a problem ;) Commented Dec 13, 2011 at 10:25
  • also i am assuming that test.data is a valid array and declared Commented Dec 13, 2011 at 10:32
  • dotSlide.functionName is present on my code.. I just forgot to put it above... See my revision Commented Dec 13, 2011 at 10:37
  • callBack: "javascript:"+dotSlide.functionName+"("+i+","+divItems+");"}) is my code because i have another code that inserts this callback in an <a href> Commented Dec 13, 2011 at 10:39
  • see my solution and instead of adding the whole function to your object you could add something like that : function(x,y){ callBackCredits(x,y);} // ... ( make sure to rename the vars ;) ) then leave the function in your code so your href still works :) ... ill edit my solution too :) Commented Dec 13, 2011 at 10:42

3 Answers 3

1

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)

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

1 Comment

i am guessing the problem is the string around "javascript: .... " the code is expecting a function and is getting a string but i am not 100% sure
1

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?

Comments

0

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

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.