Search code examples
javascriptadobe-illustrator

illustrator script, If the value of box1 is greater than Box2, give alert


enter image description here The same script has 2 different results. When I write 4 digits. I get this error. Where may be wrong.

var win = new Window('dialog', "Example");

win.size = [280,200];

var columns = win.add("group"); columns.spacing=5;

var width = columns.add('edittext {text: "", characters: 5, justify: "center"}');

var length = columns.add('edittext {text: "", characters: 5, justify: "center"}');

var height = columns.add('edittext {text: "", characters: 5, justify: "center"}');

width.active = true;


var grp = win.add('group');

var ok = grp.add('button {text: "OK"}')

grp.add('button {text: "Cancel"}');


var doBox = function(){

var box1=width.text;

var box2=length.text;

box1=width.text;

box2=length.text;

if (box1>box2)

   alert("You have entered a big number in the 1st box !");

else 

   alert("Ok");

}   

ok.onClick = doBox;

win.show();

Solution

  • Please see this answer, for why this happens. to correct this problem you can use parseInt method. To do that just change these lines

    box1=width.text;
    box2=length.text;
    

    to

    box1=parseInt(width.text);
    box2=parseInt(length.text);