Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript not working without alerts

 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
we are facing a weird problem. it goes something like this: we wrote a javascript function in a js file which enables and disables some fields and called that function from our UI page. now, in the beginning, it was not working. so, in order to test the flow, we put some alerts in it and, to our surprise, it started working (the function got called). we removed the alert, and again the function stopped responding.
can anyone rescue us of this strange problem?
Thanks in advance.
Romit
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us a sample of the code?

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a timing problem. Alerts stop thing long enough for everything to catch up.

Do you have inline code that executing before the DOM has a chance to load?

And yes, without code, it's unlikely we can offer much in the way of other than guesses.
 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
please refer to the code below; the function masterViewEditActionHandler() is the function that is not getting called. as you have rightly pointed out, there are a lots of asymetric calls, which may be causing the problem.


/********************************************/



eventHandlers.onCaseDisplay = function(){
.
.
.
.
var countryCode=document.getElementById("CountryCode").value;
var uniqueKey=Math.random()*11;
var CMSCaseID = document.getElementById("CaseID").value;
customerTypePickList(countryCode, CMSCaseID, uniqueKey);
//AJAX CALL
rootCauseCatCodeDisplayCO2Picklist(countryCode, CMSCaseID,uniqueKey);
//AJAX CALL
rootListReso(countryCode, CMSCaseID, uniqueKey);
//AJAX CALL
//OnenDone Dependent pick list call
rootCauseOnenDonePicklist(countryCode,CMSCaseID, uniqueKey);
getOnenDoneList(countryCode);
//AJAX CALL
loadCo1Lists(countryCode,CMSCaseID, uniqueKey);
//AJAX CALL
//reso 6 pick list
loadRESODivPickLists(countryCode, CMSCaseID, uniqueKey);
//AJAX CALL
multiSelectEnable();
showAssignToRESORow();
bussinessLogicOnCaseDisplay();
//hideActionsInCO();

disableAllFields();

var arrExpandosElements=getAllExpandos();
var oUserDOM = RemoteFunctions.getUserDOM();
var vBp8Role = oUserDOM.DOM.documentElement.selectSingleNode( "UserProfile/Profile" ).nodeTypedValue;
var userName = oUserDOM.DOM.documentElement.selectSingleNode( "UserProfile/User/Name" ).nodeTypedValue;

if(vBp8Role == "BCA"||vBp8Role == "DCA"||vBp8Role == "Manager"|| vBp8Role == "Administrator"||vBp8Role == "Supervisor") {
/***************THE CALLLER ****************/
collectUserInfo(userName);
//disableFieldsForChildCase();
.
.
.
.
.
}


if (caseQueryMode) {
disableAllFields();
}
}

function collectUserInfo(loginID)
{
var req = newXMLHttpRequest();
req.onreadystatechange = getReadyStateHandler(req, getUserInfo);
/**********************AJAX CALL****************/
req.open("POST", "/bpf_wficms/UserInfoServlet", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send("loginID="+loginID);
}
function getUserInfo(responseXML)
{
var valid = responseXML.getElementsByTagName("UserInfo");
var item = valid[0];
var value = item.getElementsByTagName("Info")[0].firstChild.nodeValue.split("|");

// userName + "|" + countryCode + "|" + deptName + "|" + divName + "|" + divCode + "|" + deptCode;
document.getElementById("UserName").value = value[0];
document.getElementById("CountryCode").value = value[1];
document.getElementById("UserDeptName").value = value[2];
document.getElementById("UserDivName").value = value[3];
document.getElementById("UserDivCode").value = value[4];
document.getElementById("UserDeptCode").value = value[5];

var userName = document.getElementById("UserName").value;
var deptName = document.getElementById("UserDeptName").value;
updateWelcomeNote(userName);

/******THIS IS THE FUNCION THAT IS NOT GETTING CALLED WITHOUT THE ALERT*************/
masterViewEditActionHandler(document.getElementById("UserName").value);
// Added by soumen on 16th August to handle all Enable-Disable logic - END


}
/********************************************/
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if I were in your shoes, I would find a way to make one single call to the server instead of all of those. Poor server! Are those calls asynchronous or synchronous?

If asynchronous, does that function that is not working depend on any of the info in those Ajax calls? If so you need to redesign your architecture here. One thing is browsers are limited to http connections out to a single domain. IE is 2. So that means all those calls would need to sit in a queue waiting to be made while the rest of the code is run.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric, Hi Bear,
Thank you so much for the replies. yes, the real problem is exactly what you have guessed. the alert that we were putting was actually delaying the process of the function call.We are trying to redesign our architecture in order to make one call to the database and then populate all the lists from that call. As a temporary fix, we have used window.setTimeout() to call the function, and its working fine.
Bear, i did not know about UBB codes since i am new to this forum, from now on i will send my codes in UBB Tags.
Thanks again to both of you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic