Search code examples
javascriptphotoshopphotoshop-script

How to pass text from one javascript function to another using ("+ text here +")


I know how to pass a number from one function to another, e.g:

button.onclick = function()
{
    csInterface.evalScript("ResizeCustom(" + 1234 + ")");

};

which would get picked up in the relevant line of the called function using:

function ResizeCustom(inputvalue) {

    desc1.putUnitDouble(cTID('Wdth'), cTID('#Pxl'), inputvalue);

};

This works successfully for me only using a number.

How do I achieve the same thing if I want to use text?

The text needs to be picked up in the receiving function in quotation marks, e.g:

function SelectLayer(inputtext) {

    ref1.putName(cTID('Lyr '), "Background");

};

where I want "Background" to be replaced by inputtext, and by extension the text I enter in the first function.

Thanks!


Solution

  • I still recommend checking Davide Barranca's blog HTML extension panels (https://www.davidebarranca.com/2014/01/html-panels-tips-4-passing-objects-from-html-to-jsx/), all the questions you're asking here are answered there.

    To pass your string use csInterface.evalScript("ResizeCustom('String')"); or csInterface.evalScript("ResizeCustom('"+strVar+"')");