Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

This javascript code works in mozilla but it freezes in IE

Avatar of dmalovich
dmalovich asked on
JavaScript
8 Comments1 Solution208 ViewsLast Modified:
I've attached the code.  It works fine in mozilla and chrome but it freezes when run in IE 7 or 8.
/* Set days in month script
   Copyright (c) 2003-2010 Michel Plungjan "javascripts(a)plungjan.name" */
// Change the values below if needed:

var yearName ="txtYear";
var monthName="txtMonth";
var dayName  ="txtDay";
var formIndex = 0; /* 0 for the first form on the page, name can be used but is not valid in some validators */

var adjustYears=true; // fix the year drop down to be around now.
var yearAdjustment=-100; // how many years prior to this year
var numberOfYears = 101; // how many years in the dropdown

function setDate(theForm) {
  var ySel = document.forms[formIndex].elements[yearName];
  var mSel = document.forms[formIndex].elements[monthName];
  var dSel = document.forms[formIndex].elements[dayName];

  var year = ySel.options[ySel.selectedIndex].value
  if (!year) return
  var month = mSel.options[mSel.selectedIndex].value
  if (!month) return
  var d = new Date(year,month,0); // last day in the previous month because months start on 0
  var daysInMonth = d.getDate();
  dSel.options.length=29;// save the minimum days
  if (daysInMonth>28) for (i=29;i<=daysInMonth;i++) {
    dSel.options.length++
    dSel.options[dSel.options.length-1] = new Option(i,i)
  }
  setSelectedDate(theForm);
}
function setSelectedDate(theForm) {
  var ySel = document.forms[formIndex].elements[yearName];
  var year = ySel.options[ySel.selectedIndex].value
  var mSel = document.forms[formIndex].elements[monthName];
  var month = mSel.options[mSel.selectedIndex].value
  var dSel = document.forms[formIndex].elements[dayName];
  var day  = dSel.options[dSel.selectedIndex].value

  var mm = parseInt(month);
  if (mm<10) mm="0"+mm;
  var dd = (day<10)?"0"+day:day;
  theForm.selectedDate.value=year.substring(2)+''+mm+''+dd;
}
function setNow() {
  var now = new Date()
  var ySel = document.forms[formIndex].elements[yearName];
  var mSel = document.forms[formIndex].elements[monthName];
  var dSel = document.forms[formIndex].elements[dayName];

  var year = now.getFullYear();

  if (adjustYears) {
    var firstYear = year + yearAdjustment;
    ySel.options.length=1; // remove all but 1st option
    for (var i=firstYear, n=firstYear+numberOfYears;i<n;i++) {
      ySel.options.length++
      ySel.options[ySel.options.length-1] = new Option(i,i)
    }
  }
  var minYear = parseInt(ySel.options[1].value);
  var diff = year-minYear+1;
  ySel.selectedIndex=((diff)>0)?diff:0;

  mSel.selectedIndex = now.getMonth()+1;
  dSel.selectedIndex = now.getDate(); // NB: Not 0 based
  setSelectedDate(document.forms[formIndex]);
 
}
var data = "";
window.onload=function() {
  setNow();
}
var saveDate = "";
function findIt(theForm) {
  if (saveDate) document.getElementsByName('a'+saveDate)[0].style.backgroundColor='white'
  var date = theForm.selectedDate.value;
  var anchor = document.getElementsByName('a'+date);
  if (anchor.length==0) {
    alert('The Market was closed on this day');
    return;
  } 
  anchor[0].style.backgroundColor='red'
  anchor[0].scrollIntoView();
  saveDate=date;
}
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers