Browser Widget LC button to fill and submit form

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adxsoft
Posts: 26
Joined: Wed Apr 11, 2018 12:25 pm

Browser Widget LC button to fill and submit form

Post by adxsoft » Thu Sep 05, 2019 8:06 am

Using the Browser Widget in LC8/9, I have retrieved an html page from my web server that has several input fields in an html form and am trying to figure out how to write some LC code that can fill in the input fields and submit the web page. In this way I can achieve my objective to use LC to sign into my web server, perform some queries and return my stats data back to a LC field or grid.

Any help appreciated

Allan

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Browser Widget LC button to fill and submit form

Post by [-hh] » Sat Sep 07, 2019 8:59 pm

You can do all that from LC with JavaScript (no other way).
Simply use do <string> in widget "Browser".
Important: The <string> has to be ONE line, use ";" between JS commands.

For example (the field containes no quotes, use single quotes as \' instead or work around).

Code: Select all

on mouseUp
  put fld "Textarea" into str
  replace cr with "\n" in str
  do "document.getElementById('myTextarea')." & \
     "value='" &str& "';" in widget "Browser"
end mouseUp
p.s. Questions to widgets, especially the browser widget, are better visible in the LCB forum (LiveCode Builder).
shiftLock happens

SparkOut
Posts: 2896
Joined: Sun Sep 23, 2007 4:58 pm

Re: Browser Widget LC button to fill and submit form

Post by SparkOut » Sat Sep 07, 2019 10:28 pm

Well you can't go wrong with help from Hermann, but if your objective is to log in and download data to view in LiveCode rather than interacting with a browser widget, you might find it possible to do this directly in LiveCode script (as opposed to LCB and/or javascript to leverage browser widget functionality)
This thread is old but still workable and may give some ideas viewtopic.php?f=7&t=16602&p=87985

mrcoollion
Posts: 723
Joined: Thu Sep 11, 2014 1:49 pm

Re: Browser Widget LC button to fill and submit form

Post by mrcoollion » Sun Sep 08, 2019 11:42 am

Maybe this java browser integration tutorial can help ?
Livecode Javascript communication
https://www.youtube.com/watch?v=xI_4PS_18uM&t=19s

regards,

Paul

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Browser Widget LC button to fill and submit form

Post by [-hh] » Tue Sep 10, 2019 11:34 am

The method described in the tutorial uses the revBowser external. This is available since LC 6.7.
So nothing new, but some thing is old:

The newer HTML5 (canvas) methods, say past 2010, are supported by revBrowser ONLY on Mac, NOT on Windows.

So be aware of that when using newer HTML5 methods/libraries with that external.
But using javascript in a browser widget works on Mac, Win and all Ubuntu flavours.
shiftLock happens

adxsoft
Posts: 26
Joined: Wed Apr 11, 2018 12:25 pm

Re: Browser Widget LC button to fill and submit form

Post by adxsoft » Sat Apr 11, 2020 3:08 am

Thanks everyone. Used the Javascript approach and now submitting forms successfully.
Cheers
Allan

simon.schvartzman
Posts: 652
Joined: Tue Jul 29, 2014 12:52 am

Re: Browser Widget LC button to fill and submit form

Post by simon.schvartzman » Tue Jan 05, 2021 7:43 pm

Hi all, I's like to use the Javascript approach to submit a form to upload a file to a web server. I'm confussed about to what exactly 'myTextarea' is referring to in the piece of code provided by Hermann

Code: Select all

on mouseUp
  put fld "Textarea" into str
  replace cr with "\n" in str
  do "document.getElementById('myTextarea')." & \
     "value='" &str& "';" in widget "Browser"
end mouseUp
Just to make myself more clear the page I want to "cheat" looks like this
Screen Shot 2021-01-05 at 15.38.46.png
Screen Shot 2021-01-05 at 15.38.46.png (8.29 KiB) Viewed 10983 times


and I'd like my LC script to fill in the file name (which I already know) and "press" the Submit button.

I'd really appreciate any help with it.
Many thanks in advance
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Internet”