I am not too experienced with js, but am somewhat familiar with scripting languages such as PHP. In an effort to great away from using jQuery so I started to experiment and developed the following script… which WORKS.
<script type="text/javascript">
function ajaxRequest(){
var request
try{ request = new XMLHttpRequest();}
catch (e){
try{request = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try{ request = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e){
alert("Your browser broke!");
return false;}
}
}
return request
}
function AJX(a, targ){
test=ajaxRequest();
test.onreadystatechange = function(){
switch (this.readyState) {
case 4:
document.getElementById(targ).innerHTML=this.responseText;
if (document.getElementById(targ).onchange) {document.getElementById(targ).onchange();}
break;
}
};
test.open("GET",a, true);
test.send(null);
}
function set(target){
for (el in target){
LMNT= document.getElementById(target[el][0]);
LMNT.tg=target[el][1];
LMNT.ty=target[el][2];
LMNT.onchange= function(){AJX(this.tg+this.value+"."+this.ty, this.tg); }
}
if (document.getElementById(target[0][0]).onchange) {document.getElementById(target[0][0]).onchange();}
}
var stack=[new Array('gender','names','html'),new Array('names','loc','html') ];
</script>
My question is why do I HAVE to create properties for HTML elements? In other words, this works
LMNT= document.getElementById(target[el][0]);
LMNT.tg=target[el][1];
LMNT.ty=target[el][2];
LMNT.onchange= function(){AJX(this.tg+this.value+“.”+this.ty, this.tg);
BUT
document.getElementById(target[el][0])onchange= function(){AJX(target[el][1]+this.value+“.”+target[el][2], target[el][1]);
causes ALL element to assume the LAST value of the target[el] array in the loop. I thought since I was creating a function to be stored in the element’s onchange method that all the values at the time that function would be stored there as well. obviously tha’ts not the case. Am I missing something about the way js objects function?