Set value using clipboard text, PageInst.Evaluate(document.getElementById) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
siomosp
Posts: 27
Joined: 18 Jan 2022, 10:21

Set value using clipboard text, PageInst.Evaluate(document.getElementById)

Post by siomosp » 23 Oct 2022, 03:35

Hello
using Chrome.ahk I can set an element value (text field), with this code

Code: Select all

PageInst.Evaluate("document.getElementById('delivery_message').value='some_value';")
I want the value to be a text copied manually
This code is not working, any ideas why

Code: Select all

PageInst.Evaluate("document.getElementById('delivery_message').value=clipboard;")
Full script

Code: Select all

#Include C:\Permament\ahk\Chrome.ahk_v1.2\Chrome.ahk
F1::
#SingleInstance, Force
; clipboard already contains a copied text

PageInst := Chrome.GetPage()
;PageInst.Evaluate("document.getElementById('delivery_message').value='some_value';")
PageInst.Evaluate("document.getElementById('delivery_message').value= clipboard;")

User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Set value using clipboard text, PageInst.Evaluate(document.getElementById)  Topic is solved

Post by boiler » 23 Oct 2022, 05:18

You haven’t done anything to tell it that you want the value of the variable Clipboard instead of the text “clipboard”. To correct only the AHK syntax of what you have would be like this:

Code: Select all

PageInst.Evaluate("document.getElementById('delivery_message').value=" Clipboard ";")

However, the javascript syntax that you are creating with this string would only be correct if the text in the clipboard already contained single quotes around it, such as 'some_text'. But it probably doesn’t, and actually is more like some_text, so your code needs to add them and it would be like this:

Code: Select all

PageInst.Evaluate("document.getElementById('delivery_message').value='" Clipboard "';")

siomosp
Posts: 27
Joined: 18 Jan 2022, 10:21

Re: Set value using clipboard text, PageInst.Evaluate(document.getElementById)

Post by siomosp » 23 Oct 2022, 08:36

Code: Select all

PageInst.Evaluate("document.getElementById('delivery_message').value='" Clipboard "';")
This code works like a charm
Thank you!
:bravo: :bravo: :bravo:

Post Reply

Return to “Ask for Help (v1)”