Hi,
I posted this request for help on the AJAX forum but now I discovered the problem does not have anything to do with AJAX. I re-post it here:
Hello,
I am not a Javascript expert and if possible I would like to have some help with this problem. I have the following simple HTML where I create a new MyForm object.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html lang="en" dir="ltr" >
<head>
<script src="http://lxplus012.cern.ch:1972/temporary/WebLib.js" ></script>
<link type="text/css" href="http://lxplus012.cern.ch:1972/temporary/style.css" rel="stylesheet" />
<meta http-equiv="pragma" content="no-cache" />
</head>
<script type="text/javascript" >
var myform = new MyForm('myform');
</script>
<h1 style="font-family: arial" >Elements Status</h1>
<p id="formsParId" >
</p>
<body onload="printList()" >
</body>
</html>
Then I have my WebLib.js javascript where I have several functions: one of them is the printList() function called inthe HTML. The other is makeHttpRequest() which is called when i press a button on my web page. Here a snippet of my .js file:
Code:
function makeHttpRequest()
{
printList(); // I simplified this function (where AJAX is used) to only call printList()
return;
}
////////////////////////////////
function MyForm(name){
this.name=name;
MyForm.list[name]=this
};
/////////////////////////////////////////////
function printList(){
alert("printList");
for(var i in MyForm.list){
alert("Found form i="+i);
}
}
My problem is that if I call printList() from my HTML using onload="printList()" then everything is fine and my MyForm.list is not 0 , i.e. I get to the line alert("Found form i="+i);
If I get rid of the call to printList() in HTML above and I call printList() inside the function makeHttpRequest(), then it does not find anithing in MyForm.list, i.e. I only get to the
first line alert("printList") in printList(); Does anybody know why? Is there a way to solve this keeping the declaration "var myform = new MyForm('myform');" in the HTML ?
Can anybody help please?
Thanks in advance!
Lore