Copy link to clipboard
Copied
I would like to perform a simple calculation on a selected number using Javascript in InDesign CC.
To be clear, the script should get the selected number in a variable, perform a small calculation on it, and finally replace the selected text by the result.
Can someone help me on my way? Thanks!
Good point!
Copy link to clipboard
Copied
Well, presuming the user has selected some text, and to make sure it's a number:
myNumber = Number(app.selection[0].contents);
// Do a calculation
myNumber = myNumber + 5;
// Replace the selection
app.selection[0].contents = myNumber;
That's the basic skeleton of your script, I suppose...
HTH,
Ariel
Copy link to clipboard
Copied
app.selection[0].contents = String (myNumber);
P.
Copy link to clipboard
Copied
Good point!
Copy link to clipboard
Copied
Ariel,
Thanks a lot for your suggestion, it works and I am on my way.
Regards,
Peter