3

I cannot get an applescript variable to be recognized within a do Javascript block. Previous versions of Script Editor seem to recognize the variable, but not Yosemite.

set myVar to 123
tell application "Safari" 
do Javascript " document.getElementById('filter1FieldValueId').value= dsid ;" in front document  
end tell

This is one of the various tasks I need to accomplish, and if anyone can suggest how to give JavaScript a variable outside of the DO JAVASCRIPT, that would be so helpful..

1 Answer 1

4

You need to concatenate the string together into a valid JavaScript string using the concatenate & operator. AppleScript will not interpret variables in a string.

set myVar to 123
tell application "Safari" 
    do Javascript " document.getElementById('filter1FieldValueId').value= " & myVar & " ;" in front document  
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.