I'm using a jQuery chained select dropdown box from this site/script. I put it in the sidebar and it works fine on the homepage but it isn't working on post pages and the debugger points out this error.
Uncaught TypeError: Object function ()
{for(var a=[];this.length;)a.push(this.splice(Math.random()*this.length,1));
for(;a.length;)this.push(a.pop());return this} has no method 'replace'
It says there's an error in escapeQuotes : function(str) {return str.replace(/([""\\])/g, "\\$1");
The beginning of the script:
(function($) {
$.dynamicDropdown = {
/**
* Escape quotation marks and slashes
* @param {String} String to format
* @return {String}
*/
escapeQuotes : function(str) {
return str.replace(/([""\\])/g, "\\$1");
},
Here's how I call the function. I'm using a json file to pull the options text and value into the selected boxes :
$(document).ready(function(){
$.getJSON('suggest.json', function(data){
var $select = $('#mySelectID');
$.each(data, function (index, o) {
var $option = $("<option/>").attr("value", o.Box1ID + ":" + o.Box3).text(o.Box1 + "|" + o.Box2 + "|" + o.Box3);
$select.append($option);
});
$("#mySelectID").dynamicDropdown({"delimiter":"|"});
});
});
Edited:
It seems that there's a conflict with a random image rotator I just put on the site. I temporarily removed the rotator and the chained select box is working fine. Here's an example to show the error. And this is without the random rotator.
Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1));
while (s.length) this.push(s.pop());
return this;
}
var picData = [
['img1','url_1'],
['img2','url_2'],
['img3','url_3'],
picO = new Array();
randIndex = new Array(); //array of random indexes
for(i=0; i < picData.length; i++){
picO[i] = new Image();
picO[i].src = picData[i][0];
picO[i].alt = picData[i][1];
randIndex.push(i);
}
randIndex.shuffle();
window.onload=function(){
var mainImgs = document.getElementById('carouselh').getElementsByTagName('img');
for(i=0; i < mainImgs.length; i++){
mainImgs[i].src = picO[randIndex[i]].src; //assign a random image
mainImgs[i].parentNode.href = picData[randIndex[i]][1];
mainImgs[i].alt = picData[randIndex[i]][1];
}
}