• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Safari: When do changes to a <textarea> show up in AppleScript "get the text..."
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Safari: When do changes to a <textarea> show up in AppleScript "get the text..."


  • Subject: Fwd: Safari: When do changes to a <textarea> show up in AppleScript "get the text..."
  • From: Jerry Kilpatrick <email@hidden>
  • Date: Wed, 21 Oct 2009 12:25:56 -0500

I have experimented with the ideas provided by Mark and Roger and have come up with the following simple HTML:

------------
<html>
<head>
<title>Display Text Area</title>
</head>
<body>
<textarea cols="30" rows= "5" name="name" id="id" class="class">This is it!</textarea>
</body>
</html>
-------------

and the following simple script:

-------------
tell application "Safari"
tell document 1
set byName to do _javascript_ "document.getElementsByName('name')[0].value"
set byTagName to do _javascript_ "document.getElementsByTagName('textarea')[0].value"
set byID to do _javascript_ "document.getElementById('id').value"
set byClassName to do _javascript_ "document.getElementsByClassName('class')[0].value"
end tell
display dialog byName with title "byName"
display dialog byTagName with title "byTagName"
display dialog byID with title "byID"
display dialog byClassName with title "byClassName"
end tell


tell application "Safari"
tell document 1
set byFunction to do _javascript_ "
function findTextArea() {
var i, textAreas;
textAreas = document.getElementsByTagName('textarea');
for (i=0; i<textAreas.length; i++) {
if (textAreas[i].name == 'name') {
return textAreas[i].value;
}
}
}
findTextArea();"
end tell
display dialog byFunction with title "byFunction"
end tell
---------------

All of the cases in the script will display the contents of the text area as specified in the original HTML.  The also will display the contents of the modified text if I manually change the contents of the text area by typing a new value into is.

Thanks again,

Jerry

Begin forwarded message:

From: Jerry Kilpatrick <email@hidden>
Date: October 21, 2009 9:46:45 AM CDT
To: Roger Howard <email@hidden>
Cc: "\"Mark J. Reed\" <email@hidden>Applescript Users" <email@hidden>
Subject: Re: Safari: When do changes to a <textarea> show up in AppleScript  "get the text..."

Mark and Roger,

Thanks for your responses on this.  I believe this info will get me started in the right direction.

Jerry

On Oct 20, 2009, at 5:23 PM, Roger Howard wrote:


On Oct 20, 2009, at 3:19 PM, Mark J. Reed wrote:

Or if the textarea has an id="someid" attribute, Yup, that's what I
had in mind when I said you'd have to use _javascript_.

A couple alternatives for finding the textarea from _javascript_.
First, if it has an id="someid" attribute, this will work no matter
where it is:

"document.getElementById('someid').value"

Second, if it's the only textarea on the page:

"document.getElementsByTagName('textarea')[0].value"

Or if you're using Jquery on that page, which I greatly prefer,

$("#someid").val();

Cheers!



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: watermark
  • Next by Date: Re: watermark
  • Previous by thread: Re: AS Bug?
  • Next by thread: trying to change Address Book phone labels
  • Index(es):
    • Date
    • Thread