Hi guys,
I'm a bit puzzled by a script I'm trying to write. I'm doing a script which wil automatically generates a series of commands which can then be executed by a third party application. Very simply explained, I'm generating a series of commands and I export that to a txt-like file.
I've done this before without any problems but now I've got something strange going on. I implemented a sort function which seems to work fine when I use it stand-alone. But when I copy the code into my big script, it doesn't work anymore. I checked the script for duplicate names but there aren't any. The only thing what I'm doing different then in the stand-alone script, is that I create new items in an array in different functions. However in the stand-alone script that is also in a function and there it works perfectly.
Could it be because I'm not supposed to split arrays in pieces? Although when I look at the code, I don't think I'm doing anything wrong with it.
This is the stand-alone version which works fine:
A quick explain to what the function is doing: It puts two values in a textarea (test.dko & test1.dko) and then sorts on the value from low to high. So in the list test1.dko should be first and test.dko should be second.
The code for my big script cannot be pasted here since it's over 1200 lines big. But I can send it to you upon request and e-mailaddress.
The only thing I changed there is that I'm putting
in a few different functions but all with different values. So I'm actually trying to add new items to the array depending on which functions are being called.
When I put the
at the top where I define the array then it works without a problem but that's not the effect I'm going for.
Does anyone have a clue why this won't work ?
Thanks for the help!
I'm a bit puzzled by a script I'm trying to write. I'm doing a script which wil automatically generates a series of commands which can then be executed by a third party application. Very simply explained, I'm generating a series of commands and I export that to a txt-like file.
I've done this before without any problems but now I've got something strange going on. I implemented a sort function which seems to work fine when I use it stand-alone. But when I copy the code into my big script, it doesn't work anymore. I checked the script for duplicate names but there aren't any. The only thing what I'm doing different then in the stand-alone script, is that I create new items in an array in different functions. However in the stand-alone script that is also in a function and there it works perfectly.
Could it be because I'm not supposed to split arrays in pieces? Although when I look at the code, I don't think I'm doing anything wrong with it.
This is the stand-alone version which works fine:
Code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
var seq = "";
function test() {
people[people.length++] = new item("test.dko", "2");
people[people.length++] = new item("test1.dko", "1");
}
var people = new Array();
function item(file, nr) {
this.file = file;
this.nr = parseInt(parseFloat(nr));
}
function sortNr(a, b) {
var x = a.nr;
var y = b.nr;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
function sortArray() {
people.sort(sortNr);
for (var i=0; i<people.length; i++) {
seq += people[i].file + (i+1)+" \n";
}
document.Demo.Results.value = seq;
}
// -->
</script>
</head>
<body>
<form name="Demo" method="post" action="/" onsubmit="return false;">
<input type="button" value="Sort By Age" onclick="sortArray()" />
<br />
<input type="button" value="Stest" onclick="test()" />
<textarea name="Results" onfocus="this.blur();" rows="20" cols="60"></textarea>
</form>
</body>
</html>
The code for my big script cannot be pasted here since it's over 1200 lines big. But I can send it to you upon request and e-mailaddress.
The only thing I changed there is that I'm putting
Code:
people[people.length++] = new item("file.dko", "2");
When I put the
Code:
people[people.length++] = new item("file.dko", "2");
Does anyone have a clue why this won't work ?
Thanks for the help!
Comment