Skip to main content
added 1018 characters in body
Source Link
epascarello
  • 207.8k
  • 20
  • 206
  • 246

getCstMsgName is a string, not an array.

One way is to use this

$(document).ready(function () { var testName_MessagesArray = new Array(); var cntr = 0; testName_MessagesArray[cntr] = new Array("testName_custom_message_Label1val", "Custom message for label 1"); cntr++; testName_MessagesArray[cntr] = new Array("testName_custom_message_Label2val", "Custom message for label 2"); cntr++; alert(testName_MessagesArray[1][1]); var classChk = $(".customCheckEnabled"); alert(classChk); this.testName = testName_MessagesArray; //<-- set this with the name var getClassindex = classChk.attr("selectedIndex"); alert(getClassindex); var getVarName = classChk.attr("id"); alert(getVarName); var getCstMsgName = this[getVarName]; //<-- reference it from this alert(getCstMsgName); var getMessage = getCstMsgName[getClassindex][1]; alert(getMessage); }); 

​ If testName_MessagesArray is in global scope, you can do window["testName_MessagesArray"] to reference it. Your current example is local scope so that would not work.

getCstMsgName is a string, not an array.

getCstMsgName is a string, not an array.

One way is to use this

$(document).ready(function () { var testName_MessagesArray = new Array(); var cntr = 0; testName_MessagesArray[cntr] = new Array("testName_custom_message_Label1val", "Custom message for label 1"); cntr++; testName_MessagesArray[cntr] = new Array("testName_custom_message_Label2val", "Custom message for label 2"); cntr++; alert(testName_MessagesArray[1][1]); var classChk = $(".customCheckEnabled"); alert(classChk); this.testName = testName_MessagesArray; //<-- set this with the name var getClassindex = classChk.attr("selectedIndex"); alert(getClassindex); var getVarName = classChk.attr("id"); alert(getVarName); var getCstMsgName = this[getVarName]; //<-- reference it from this alert(getCstMsgName); var getMessage = getCstMsgName[getClassindex][1]; alert(getMessage); }); 

​ If testName_MessagesArray is in global scope, you can do window["testName_MessagesArray"] to reference it. Your current example is local scope so that would not work.

Source Link
epascarello
  • 207.8k
  • 20
  • 206
  • 246

getCstMsgName is a string, not an array.