0

I have this code on jsFiddle. http://jsfiddle.net/crashdesk/GbUZ9/

There appears to be a problem in IE7 where it throws an error:

Object doesn't support property or method 'indexOf'

For the life of me I can't seem to fix it.

Can some javascript guru out there help me with this one.

Many thanks, C

2 Answers2

0

Got it sorted in a somewhat hack way. I had to create a string for IE7 aswell as the array for all other browsers.

Used information from here...http://minimalbugs.com/questions/share-solve-javascript-error-on-ie-related-to-indexof-function

Hopefully this will be of some help to someone else. Phew!

var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
            var months2 = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";

                // initialise the "Select date" link
                $('#date-pick')
                    .datePicker(
                        // associate the link with a date picker
                        {
                            createButton:false,
                            endDate:'31/12/2012'
                        }
                    ).bind(
                        // when the link is clicked display the date picker
                        'click',
                        function()
                        {
                            updateSelects($(this).dpGetSelected()[0]);
                            $(this).dpDisplay();
                            return false;
                        }
                    ).bind(
                        // when a date is selected update the SELECTs
                        'dateSelected',
                        function(e, selectedDate, $td, state)
                        {
                            updateSelects(selectedDate);
                        }
                    ).bind(
                        'dpClosed',
                        function(e, selected)
                        {
                            updateSelects(selected[0]);
                        }
                    );

                var updateSelects = function (selectedDate)
                {
                    var selectedDate = new Date(selectedDate);
                    $('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
                    $('#m option[value=' + (months[selectedDate.getMonth()]) + '-' +  (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
                }
                // listen for when the selects are changed and update the picker
                $('#d, #m')
                    .bind(
                        'change',
                        function()
                        {
                            var d = new Date(
                                        $('#m').val().split("-")[1],
                                        months2.indexOf($('#m').val().split("-")[0]),
                                        $('#d').val()
                                    );
                            $('#date-pick').dpSetSelected(d.asString());

                        }
                    );

                // default the position of the selects to today
                var today = new Date();
                updateSelects(today.getTime());

                // and update the datePicker to reflect it...
                $('#d').trigger('change');
        }
-1

Here: http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/

Calum
  • 5,308
  • 1
  • 22
  • 27
  • Thanks. Read up about that and tried integrating with the jsFiddle code but still throws error. :-( –  Aug 09 '11 at 08:57
  • IE is messed up! Try this: http://stackoverflow.com/questions/2608575/jquery-split-and-indexof-results-in-object-doesnt-support-this-property-or-me – Calum Aug 09 '11 at 09:04