简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM