Page 1 of 1
How to read/write from HTML-Form Element? (JavaScript?)
Posted: Sun Jul 16, 2017 10:24 am
by PureLust
I've already discovered how to write/set attributes to simple HTML Input-Elements in a WebGadget (like 'text'-, 'checkbox'- or 'submit'-Types).
The way I set attributes/values right now is:
Code: Select all
Command1$ = "void(document.forms[0].[InputField-NAME].value='NewText');" ; example for setting the text of an Input-Element
Command2$ = "void(document.forms[0].[CheckBox-NAME].checked='1');" ; example for checking a CheckBox
Command3$ = "void(document.forms[0].[Button-NAME].click());" ; example for clicking a Button (an Input-Submit-Element)
SetGadgetText(#Gad_WebGadget, "javascript:" + Command3$)
SetGadgetState(#Gad_WebGadget, #PB_Web_Back)
I'm not sure if this is 'the best way' ... but at last it seams to work.
What I was not able to find out, is:
- how to set attributes/values of more complex Elements (like a
TABLE >
ITEM >
FIELD).
- and even more important for me - how to
READ values from Elements (like
INPUT or specific
FIELDS out of a
TABLE)
Does anyone has an Idea how this could be done?
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 5:51 am
by JHPJHP
Enhanced PureBasic / JavaScript examples:
-
Barcode Generator,
Embed JS into PureBasic,
Geolocation: Google Maps
PureLust wrote:how to set attributes/values of more complex Elements (like a TABLE > ITEM > FIELD).
Build the HTML, JS, CSS from a string value:
WebGadget; FEATURE_BROWSER_EMULATION; Windows 10;
- optionally, only that part of the script you need modified, the rest can be loaded from a separate file or include
PureLust wrote:and even more important for me - how to READ values from Elements (like INPUT or specific FIELDS out of a TABLE)
Any information you need access to can be placed in the
PageTitle attribute (
#PB_Web_PageTitle) using a JavaScript EventListener, etc.
-
Monitor Changes: an alternative to the
#PB_EventType_TitleChange event (Windows only) is a PureBasic timer event
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 8:44 am
by HanPBF
Hello JHPJHP,
is JavaScript
the correct way to access the content after
Code: Select all
SetGadgetItemText(WebMain, #PB_Web_PageTitle, P)
?
With my code, it seems that document.title is not set by PureBasic.
I tried event DOMSubtreeModified observation which did not work. So, I checked everything by using
Code: Select all
window.setInterval(function (){
alert(document.title);
if(document.title!=PB.Title){
alert('onreceive');
PB.onReceiveMessage(document.title);
}
}, 5000);
The timeout of 5000ms and the first alert show me that nothing changed indeed.
Is there any setting needed in IE?
Thanks a lot for any help!
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 8:47 am
by HanPBF
Funny; I saw an evidence for the behaviour.
Code: Select all
SetGadgetItemText(WebMain, #PB_Web_PageTitle, "...")
debug GetGadgetItemText(WebMain, #PB_Web_PageTitle) ;This is not given back the same result:
Now, for me it seems there must be a silly error somewhere in my code...
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 9:02 am
by HanPBF
Damn;
From PureBasic help:
Code: Select all
- SetGadgetItemText(): With #PB_Web_HtmlCode as 'Item' html code can be streamed into the Gadget. (Windows only)
- GetGadgetItemText(): The following constants can be used to get information (Windows only):
Seems, only reading but not writing for #PB_Web_PageTitle is supported:-(
For a single page application using set of #PB_Web_HtmlCode is not so good.
Any other idea???
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 9:13 am
by HanPBF
The only workaround I have found is to use writing a file to the file system and seeking it with JavaScript.
Code: Select all
var FS = new ActiveXObject('Scripting.FileSystemObject');
var Path = '...';
if(FS.FileExists(Path + 'Message.json')){
alert('onreceive');
}
Annoying...
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 4:03 pm
by JHPJHP
Hi
HanPBF,
Use the PageTitle attribute to store data set from a JavaScript ListenerEvent, etc. If needed monitor PageTitle for a change, either with a PureBasic
#PB_EventType_TitleChange event (Windows only) or a PureBasic timer event.
Instead or writing to PageTitle, create a response string and
SetGadgetItemText again.
- see:
Embed JS into PureBasic --
Flot_PieChart.pb (includes/flot_piechart.pbi) [
Generate Random Data ]
Another group of examples that demonstrate what I'm referring to can be found in
Geolocation: Google Maps...
... The entire HTML page is held in a string variable, with various configurable values retrieved from PureBasic Gadgets. The modified string variable (HTML page) is manually submitted back to the WebGadget, making a web-service request.
Re: How to read/write from HTML-Form Element? (JavaScript?)
Posted: Mon Jul 17, 2017 5:18 pm
by HanPBF
Hello JHPJHP,
I don't get it. Can't see in Your examples how a "server" push is realized.
But, working with local file is o.k.. As I said, I don't change the URL, I use a single page application.
I even could embed a script which is updated every 500ms to poll "server" pushes/callbacks.
Better would be using Websocket library from Danilo... but is too much for my scenario.
Thanks again for the info!