Reputation: 47
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>
Upvotes: 1
Views: 105
Reputation: 23416
item
is a protected property of the window object in IE. Just rename your variable, or declare it properly (using var
) in your function.
Upvotes: 1
Reputation: 7152
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); }
Upvotes: 0