9

I have cascaded dropdown in my application, cascaded using jquery, now my problem is it is working smoothly with IE9, Firefox, Opera and Safari but does not work with any of browsers like IE7,IE8 etc.

I surfed for the problem and found that error is due to indexOf in my jquery code, i tried it by removing indexOf but still it is giving the same error..

Note: Is there any work around in telerik script to remove indexOf, coz new only i can find indexOf in their script.

Below is the Code:

function OnClientSelectedIndexChanged(sender, eventArgs) { var senderId = sender.get_id().toString(); var uniqueName = senderId.substring(senderId.lastIndexOf('_'), senderId.length); if(senderId.indexOf("drpdwnCondition") > 0) { return false; } var selectedItem = eventArgs.get_item(); var selectedValue = selectedItem.get_value().split('_'); $.ajax({ type: "POST", async: true, url: "/SalesRepresentativeMonitoring.aspx/GetData", contentType: "application/json; charset=utf-8", data: "{value:" + JSON.stringify(selectedValue[1]) + "}", dataType: "json", success: function (msg) { var resultAsJson = msg.d // your return result is JS array // Now you can loop over the array to get each object var cnditionCombo = $find("ctl00_ContentPlaceHolder1_radDock_C_Filter_drpdwnCondition" + uniqueName.toString()); cnditionCombo.clearSelection(); cnditionCombo.trackChanges(); cnditionCombo.clearItems(); for (var i in resultAsJson) { //alert(resultAsJson[i]); var item = new Telerik.Web.UI.RadComboBoxItem(); item.set_text(resultAsJson[i]); item.set_value(resultAsJson[i]); cnditionCombo.get_items().add(item); } var itemAtIndex = cnditionCombo.get_items().getItem(0); //get item in detailCB itemAtIndex.select(); cnditionCombo.commitChanges(); } }); 

}

Thanking you..

7
  • 1
    Could you please post your code. Commented Jan 13, 2012 at 9:08
  • 1
    AFAIK, indexOf works well in ie7 and 8. Please show some code Commented Jan 13, 2012 at 9:08
  • @Archer He said that it did work in ie9, and not 7+8 :) Anyways, it should be working in all of them Commented Jan 13, 2012 at 9:14
  • The indexOf method of Arrays is not implemented in IE < 9, so I assume that's what the OP is referring to. Commented Jan 13, 2012 at 9:15
  • Correct - I take it back. However, like I said about removing it leaving the same error means that it is not the problem. Commented Jan 13, 2012 at 9:21

2 Answers 2

26

The indexOf() method of Arrays is not implemented in IE < 9. As you're using jQuery you can make use of the $.inArray(), e.g.

var arr = ["foo", "bar", "baz"], bazIndex = $.inArray("baz", arr), // 2 doesntExistIndex = $.inArray("notThere", arr); // -1 

Here's the documentation: http://api.jquery.com/jQuery.inArray/.

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

Comments

22

The documentation for indexOf on MDN includes a pollyfill that will add support in browsers that don't support JavaScript 1.6.

You can drop it in to avoid having to rewrite the existing code.

if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { "use strict"; if (this == null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (len === 0) { return -1; } var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); if (n != n) { // shortcut for verifying if it's NaN n = 0; } else if (n != 0 && n != Infinity && n != -Infinity) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); } } if (n >= len) { return -1; } var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); for (; k < len; k++) { if (k in t && t[k] === searchElement) { return k; } } return -1; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.