Javascript array.indexOf not working for me =S

Discussion in 'JavaScript' started by gsquare567, May 18, 2010.

  1. #1
    here is the begining of my function (after being generated by php on the page). the part of the code that is not working is the (reqVideos != null && reqVideos.indexOf("1") != -1 ? "selected='selected'" : "") blocks.
    function addEvent(eventID, timeInterval, since, isPeriodic, eventDesc, eventType, isOrientation, timeDesc, reqVideos) {
    		if(eventDesc != '') eventDesc = $.parseJSON(eventDesc);
    		if(timeDesc != '') timeDesc = $.parseJSON(timeDesc);
    		if(reqVideos != '') reqVideos = $.parseJSON(reqVideos); // array of video ids
    		
    		var videoOptionsHTML =
    		"<option value='1' " + (reqVideos != null && reqVideos.indexOf("1") != -1 ? "selected='selected'" : "") + ">How Defined Benefit Pensions Work</option><option value='2' " + (reqVideos != null && reqVideos.indexOf("2") != -1 ? "selected='selected'" : "") + ">Tax Free Savings Accounts</option><option value='3' " + (reqVideos != null && reqVideos.indexOf("3") != -1 ? "selected='selected'" : "") ....................
    Code (markup):
    when my other php-generated javascript calls this function (on document load), options which have value equal to a string (which is just a number) in the array are not selected!
    eg.
    (from the page source, once again)
    addEvent(2,1,1,0,"\"Meets with a fully licensed financial advisor to answer Pension & Benefits questions, assist with preparation of a Risk Assessment\\/Asset Allocation and receives \\\"fund specific\\\" investment advice upon request\"",2,0,"\"First month\"",["1"]);
    
    Code (markup):
    i have firebug installed and no javascript errors appear in the console, so it must be a logic error. can anyone see the problem?

    thanks a lot!
     
    gsquare567, May 18, 2010 IP