Input variable into Java Script

Viewed 29

I am attempting to take a list of variables that I have generated using apple automator and input those variables into my Javascript, but I haven't been having much luck. My current code looks like this:

function run(input, parameters) {

var safari = Application("Safari");
safari.includeStandardAdditions = true;

var jsScript ="jsScript += document.getElementById('search-name').value = '"
+ input[0] + input[1]
+ "';";
"jsScript += document.getElementById('search-location').value = '"
+ input[2] + input[4]
+ "';";
jsScript += "document.getElementById('wp-search').click();";

safari.doJavaScript(jsScript, { in:safari.windows[0].currentTab});

return jsScript;

}

I am getting the error can't find variable: jsScript. Please any help would be greatly appreciated.

1 Answers

Just incase there are others out there that were trying to do the same thing. I figured out the answer to my question with a little help from a co worker. The following script will take a variable and input it into a string for a webform search:

function run(input, parameters) {

var safari = Application("Safari");
safari.includeStandardAdditions = true;

var jsScript = "";
    jsScript += "document.getElementById('search-name').value = '" 
        + input[0] + " " + input[2] + "';";
    jsScript += "document.getElementById('search-location').value = '"
        + input[5] + " " + input[6] + "';";
    jsScript += "document.getElementById('wp-search').click();";

safari.doJavaScript(jsScript, { in:safari.windows[0].currentTab});

return input;

}

Related