Donnez vie à vos documents numériques !
 

Répondre à : Highlight first 2 greatest number

abracadabraPDF Forums PDF – Général Highlight first 2 greatest number Répondre à : Highlight first 2 greatest number

#69631
bebarth
Maître des clés

Hi,
I don't understand why the function doesn't work for you. I did a test on both PC and Mac and the file works fine with both OS.
As your UArr fonction works fine too, you can you it for the file.
I placed the script in an other funtion. That avoids to get it twice in the buttons:

Code:
// Document Scriprs
function UArr(a){
    var newArr=[];
    for (var i=0; i         if (newArr.indexOf(a)===-1) newArr.push(a);
    }
    return newArr;
}
function greatORsmall(wichOne) {
    var arr=[];
    for (var i=0; i<30; i++) {
        var f=this.getField(“theField.”+i);
        if (!isNaN(f.value) && f.value!=””) arr.push(f.value);
    }
    if (wichOne==”greatest”) {
        var dv=arr.sort(function(a, b){return b-a});
    } else {
        var dv=arr.sort(function(a, b){return a-b});
    }
    var myarr=UArr(dv);
    for (var i=0; i<30; i++){
        var f=this.getField(“theField.”+i);
        f.fillColor=color.transparent;
        if (f.value == myarr[0]) f.fillColor=color.red;
        else if (f.value==myarr[1]) f.fillColor=color.green;
        else if (f.value==myarr[2]) f.fillColor=color.magenta;
        else if (f.value==myarr[3]) f.fillColor=color.yellow;
    }
    this.getField(“Text1″).value=””;
    if (myarr.length!=0) {
        if (myarr.length>4) var nbNumbers=4;
        else var nbNumbers=myarr.length;
        if (nbNumbers==1) this.getField(“Text1″).value=”The unique number is:”;
        else this.getField(“Text1”).value=”The “+nbNumbers+” “+wichOne+” unique numbers are:”;
        for (var i=0; i            try {
                this.getField(“Text1”).value+=”nu2022 “+myarr;
            } catch(e) {}
        }
    }
}

// Mouse up action scripts
// greatest and smallest buttons
greatORsmall(event.target.buttonGetCaption());

// reset button
for (var i=0; i<30; i++) {
    var f=this.getField(“theField.”+i);
    f.value=””;
    f.fillColor=color.transparent;

Please try the new file and let me know.
@+
:bonjour: