views:

77

answers:

2

An OnClick event calls the following datepicker function. If an alert is present then, it works fine. Otherwise, it does not show the calender as required. Is this a timing issue?

function changeStartDate(Item){  
            alert ("alert goes here");

  $("#datepicker_" + Item).datepicker({                  
   dateFormat: 'M-dd-yy',
   onClose: function(dataText, inst){
      newDate = dataText;
                       processDateChange(newDate);
   },
  }); 

  flag = 1; 
  }

Where it is called from:

 '<div class="InfoBoxLong" id="StartDate_' + TransactionOrderItemID + '"><input id="datepicker_' + TransactionOrderItemID + '" type="text" size="9" id="StartDate_' +  TransactionOrderItemID + '" onClick="changeStartDate(\'' + TransactionOrderItemID + '\')"  value="' + ActivationStartDate + '"> </input></div>' +
+3  A: 

Possible the calender DOM hasn't finished rendering - adding an alert() blocks the page which gives it time to finish rendering. Use the equivalent of jquery.ready (http://docs.jquery.com/Events/ready#fn) to render the calender and then only show it (rather than rendering it) on the onclick event.

colinramsay
You are probably right. But, I am not sure about the ready equivalent for this.
Natkeeran
Well I see you are using $("#datepicker_" + Item), and with the $ it's likely you're using either jQuery or Prototype as a supporting library. Do you know which one it might be?
colinramsay
I am using Jquery.
Natkeeran
A: 

I changed the onClick event to onMouseOver event, and it seems to work fine. Although, I am not comfortable using it, as it will fireoff this event often. Thanks for all the responses.

Natkeeran