I’m trying to set an array with elements not numbered, but referenced with names of my selection and values of the elements in the array with my choices.
Could someone advise me as to why I get an ‘undefined’ in the alert display after entering pairs of “names” and “values” with the “Add” button?
I don’t see any JS console errors, but I don’t seem to be able to set the elements either. Any ideas?
[code=php]
<html>
<head>
<title>Array Test</title>
<script type=”text/javascript”>
NameList = {
ArrLength : 0,
ItemArray : new Array(),
initItemArray : function() { this.ArrLength = 0; },
putItem : function(item,value) { this.ItemArray[item] = value; this.ArrLength++; },
getItem : function(item) { return this.ItemArray[item]; },
showItems : function() {
var t = ”;
for (var i in this.ItemArray) {
t += i+’ : ‘+this.getItem[i]+”n”;
}
alert(‘ItemArrayn’+t);
}
}
function AddItem() {
var n = document.getElementById(‘FName’).value
var v = document.getElementById(‘FValue’).value;
NameList.putItem(n,v);
}
function Clear() {
document.getElementById(‘FName’).value = ”;
document.getElementById(‘FValue’).value = ”;
}
function Show() { NameList.showItems(); }
</script>
</head>
<body>
<input type=”text” id=”FName” value=””>Name<br />
<input type=”text” id=”FValue” value=””>Value<br />
<button onClick=”AddItem()”>Add</button>
<button onClick=”Clear()”>Clear</button>
<button onClick=”Show()”>Show</button>
</body>
</html>