tags:

views:

377

answers:

3

Hi,

I have the following JQuery code in a external JS file linked into a usercontrol in .Net 1.1 webapp.

The usercontrol is a timesheet.

When the page loads it calls MonthChange and works fine in one page.

But now I want to load the timesheet/usercontrol into aother webpage that pops up a in a new browser window for printing.

Problem is my MonthChange is not firing.

Any ideas why???

$(function() {

 MonthChange();
 //TestData();

 $('[class^=TSGridTB]').blur(function() {
  var day = GetDay($(this).attr('id'));
  var date = GetRowDate(day);
  var bgcolor = GetInputFieldColor(date, false);

  $(this).css("background-color", bgcolor);
  $(this).parent().css("background-color", bgcolor);
  //CalcHours($(this).get(0));
 });

 $('[class^=TSGridTB]').focus(function() {
  var day = GetDay($(this).attr('id'));
  var date = GetRowDate(day);
  var bgcolor = GetInputFieldColor(date, true);

  $(this).css("background-color", bgcolor);
  $(this).parent().css("background-color", bgcolor);
 });

 $('[id$=lstMonth]').change(function() {
  MonthChange();
 });   

});
A: 

without seeing further code, ensure that the selector is correct for the control in the new page.

The problem may be that the DOM has changed for the new page/window and JQuery does not yet know about it.

The change event

fires when a control loses the input focus and its value has been modified since gaining focus.

You might want to use the live event:

Binds a handler to an event (like click) for all current - and future - matched element.

When you bind a "live" event it will bind to all current and future elements on the page (using event delegation). For example if you bound a live click to all "li" elements on the page then added another li at a later time - that click event would continue to work for the new element (this is not the case with bind which must be re-bound on all new elements).

I may not have mentioned but the links to Jquery and all code are contained in the usercontrol. Just add to diffeent aspx page???
Malcolm
A: 

Did you make sure that the new web page has jQuery script includes?

bashmohandes
A: 

ensure you're using:

$(document).ready(
);

around your entire code block. The $ alone often does not do the trick.

Soviut