1

This works fine in all browsers except IE can anyone explain why so I can fix it. I am displaying the index of a javascript object based on the index of the selected index of my dropdown list

 $(document).ready(function () {
var pdata = [{ Name: "Apples", Price: 1.99 },{ Name: "Bananas", Price: 2.45 } ];

    $('#produceTMPL').tmpl(pdata).appendTo('#produceList');

      $(document).ready(function () {


      $('#add1').click(function () {
        var selected = $('#produceList option:selected').index();

        item = pdata[selected];

        console.log(selected);
        $('#cart').append('<p>' + item.Name + ', ' + item.Price + '</p>');




    });  
    });

HTML:

     <div>
  <select id="produceList">
  <option>make a selection</option>
  </select>
chrisp54
  • 47
  • 2
  • 8

2 Answers2

1

item is a protected property of the window object in IE. Just rename your variable, or declare it properly (using var) in your function.

Teemu
  • 22,918
  • 7
  • 53
  • 106
0

console.log throws an error in IE, so to be on the safer side DO NOT use console.log with out checking if browser supports it or not.

try{
    if(console && console.log) console.log('message')   
}catch(e){}

OR

 if ('undefined' !== typeof console){console.log(message); }
Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92