Natkeeran
Natkeeran

Reputation: 1749

js script works only when alert is present - not an ajax call

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>' +

Upvotes: 0

Views: 927

Answers (2)

Natkeeran
Natkeeran

Reputation: 1749

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.

Upvotes: 0

Colin Ramsay
Colin Ramsay

Reputation: 16466

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.

Upvotes: 3

Related Questions