Your script craches when the last pair cannot be made.

e.g. if the first 3 pairs becomes 1-2 , 2-4 , 4-1.

then the only possible pair left is 3-3.

as it fails to validate, the script will try over and over again, but will never succeed.

In this case a swap between a random, already set second-value and the remaining second-value is needed

Code:

<script>
value = document.myform.three.value;
Pairs=[];
for(var a=0; a<value; a++){
Pairs[a]=a+1;
}
SecondValues=Pairs.slice(0);
*// --- Create all pairs but one --- //*
for (x=0;x<Pairs.length-1;x++){
do {
C=Math.floor(Math.random()*SecondValues.length);
} while(Pairs[x]==SecondValues[C] );
Pairs[x]=[Pairs[x],SecondValues.splice(C,1)[0]];
}
*// --- Test, and swap values if last pairs can't be valid. --- //*
S=Math.floor(Math.random()*(Pairs.length-2));
if (Pairs[Pairs.length-1] == SecondValues[0]){
Pairs[Pairs.length-1]=[Pairs[Pairs.length-1],Pairs[S][1]];
Pairs[S][1]=SecondValues[0];
}else{
Pairs[Pairs.length-1]=[Pairs[Pairs.length-1],SecondValues[0]]
}
</script>

this will create:

Code:

Pairs = [[3, 1], [2, 4], [4, 3], [1, 2]]

or alike;