Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External JS File Problem

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Greetings all,

I assume this is the correct forum for this because it only happens on the client size. The page is written in XHTML ASP/VB.net 2.0, but I don't think that is the forum for this question.

The problem only happens in IE 7 (possibly 6 and 8, but I don't care about those browsers as the environment will be strictly IE7). Firefox has no problems. This is an intranet website. The problem also only happens when the javascript is in an external file and not when the code is pasted into the aspx file directly.

I have the following JS code:
Code:
var mon = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var month = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var current_date = new Date();
var cal_date = new Date();
var selected_month = cal_date.getMonth();
cal_date.setDate(1);
var toggle_fld;
var mouseX, mouseY;
if(document.getElementById('sm_cal')) create_small_calendar(0);

document.onmousemove = getXY;
function getXY(e) {
  if(document.all) {
    mouseX = window.event.clientX + document.documentElement.scrollLeft;
    mouseY = window.event.clientY + document.documentElement.scrollTop;
  } else {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
}


function create_small_calendar(act) {
  cal_date.setMonth(cal_date.getMonth() + act);
  selected_month = cal_date.getMonth();
  if(selected_month == 12) selected_month = 0;
  document.getElementById('sm_cal_title').innerHTML = mon[cal_date.getMonth()] + ' ' + cal_date.getFullYear();
  document.getElementById('sm_cal_content').innerHTML = "";
  //set the date to the sunday prior to the first and print out the rest of the current month
  cal_date.setDate(1);
  cal_date.setDate((0 - cal_date.getDay()+1));
  while(cal_date.getMonth() == (selected_month)-1 || cal_date.getMonth() == (selected_month) || (cal_date.getMonth() == 11 && selected_month == 0)) {  //starts at 11 which is greater than 1
    var day_box = "<div ";
    day_box += " onclick='select_date(this);'";
    if(cal_date.getMonth() != selected_month) day_box += " class='day othermonth'";
      else day_box += " class='day'";
    day_box += "id='"+cal_date.getMonth() + "-" + cal_date.getDate() + "-" + cal_date.getFullYear()+"'>";
    day_box += cal_date.getDate() + " ";
    day_box += "</div>";
    document.getElementById('sm_cal_content').innerHTML += day_box;
    cal_date.setDate(cal_date.getDate() + 1);
  }
  //finish printing the last week
  while(cal_date.getDay() != 0) {
    var day_box = "<div ";
    day_box += " onclick='select_date(this);'";
    if(cal_date.getMonth() != selected_month) day_box += " class='day othermonth'";
      else day_box += " class='day'";
    day_box += "id='"+cal_date.getMonth() + "-" + cal_date.getDate() + "-" + cal_date.getFullYear()+"'>";
    day_box += cal_date.getDate() + " ";
    day_box += "</div>";
    document.getElementById('sm_cal_content').innerHTML += day_box;
    cal_date.setDate(cal_date.getDate() + 1);
  }
}

function toggle_sm_cal(fld) {
  toggle_fld = fld;
  document.getElementById('sm_cal').style.left = mouseX + 10 + 'px';
  document.getElementById('sm_cal').style.top = mouseY + 10 + 'px';
  if(document.getElementById('sm_cal').style.display == 'none') {
    document.getElementById('sm_cal').style.display = 'block';
  } else {
    document.getElementById('sm_cal').style.display = 'none';
    cal_date.setTime(current_date.getTime());
    create_small_calendar(0);
  }
}

function select_date(dte) {
  var temp = dte.id.split('-');
  document.getElementById(toggle_fld).value = (parseInt(temp[0],10)+1) + '-' + temp[1] + '-' + temp[2];
  toggle_sm_cal();
}

Again, when pasted directly into the aspx file, no errors and everyone is fat dumb and very happy. When referenced:
Code:
<script type="text/javascript" src="/modules/calendar.js"></script>
I get the ever-popular "syntax error" referencing the very last character of the .js file.

Any ideas as to why this is? I do appreciate the help.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Should be in the Javascript forum, but try this and if it doesn't work, someone there should be able to help out.

on the very last line (before the closing curly brace)

Code:
toggle_sm_cal();

That function expects a single paramater

Code:
function toggle_sm_cal(fld) {
  toggle_fld = fld;
  document.getElementById('sm_cal').style.left = mouseX + 10 + 'px';
  document.getElementById('sm_cal').style.top = mouseY + 10 + 'px';
  if(document.getElementById('sm_cal').style.display == 'none') {
    document.getElementById('sm_cal').style.display = 'block';
  } else {
    document.getElementById('sm_cal').style.display = 'none';
    cal_date.setTime(current_date.getTime());
    create_small_calendar(0);
  }
}

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks for the post vicvirk.

Well, gee... don't I feel stupid for that. However, it didn't solve the issue.

The line is now changed to
Code:
toggle_sm_cal(toggle_fld);

The attempt is to simply close the small calendar.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top