Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes javascript not working without alerts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript not working without alerts" Watch "javascript not working without alerts" New topic
Author

javascript not working without alerts

Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Can you give us a sample of the code?

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Romit Bose
Ranch Hand

Joined: Oct 03, 2007
Posts: 50
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

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

Joined: Oct 03, 2007
Posts: 50
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript not working without alerts
 
Similar Threads
Across JSPs wrong JavaScript Function with the same prototype is getting called
onload
If last char of textarea is \n, Safari 3.2.1 seems to think the textarea contains extra \n.
Object Expected Error
Popup not working properly on new server