PDA

View Full Version : How do I change the value of an array


risk
10-30-2002, 11:50 PM
I want to change the value of an array element if the satisfies the if statement in the funtion displayItem()

<HTML>
<head>
<script language=JavaScript>

var info= new Array();
info[1]="15" // Hard Drive

info[2]="64 MB" // ram 64

info[3]="4.01" // IE version

info[4]="200 Mhz" // processor


function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}

function displayItem(key){

result.innerHTML+=queryString(key)+"<BR>";

if (queryString(key)=="ENTERPRISE Client")
info[1] = "hehehehe";
return info;

if (queryString(key)=="Windows 98")
info[2] = "4.01";
info[3] = "64MB"
}

</script>


<body onload="displayItem('field1'); displayItem('field2'); displayItem('field3');">

<div id=result></div>
<table>
<script language = javascript>
document.write(info[10])
</script>
</table>
</BODY>
</HTML>

joh6nn
10-31-2002, 08:45 AM
could you give some more details, please? i'm not sure i understand what your problem is.