Android Question Fill HTML Form with Result on Webview

ahmadalibeck

Member
Licensed User
Longtime User
Guys, without using JAVA because I am not doing good with it. I need to make a simple program that loads a webpage (say Google) on Webview1, after the user fills a word in a EditText, he press a button, this button copies the value in the EditText to the TextInput in (Google) webpage, then submits, then results appears on the Webview again.

The goal is not the Google, the goal is to see how to simply fill a HTML form, then load the response page on Webview again.

I believe it is easier with HttpUtills2, but I couldn't do it. From the results that I found it is easy, but I have trying for long time without progress.
 

Cableguy

Expert
Licensed User
Longtime User
See the web extras JScript object. You can inject into a forms field as long as you know the forms name and the fields names
 
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
I requested any method away from Java because I am not familiar with Java. However, from the posts mentioned above,
I wrote the following, it is not correct, what s the correct one please?

The ID of the text input element in Google page (as an example) is "lst-ib", and the form ID is "tsf" so my code is:

B4X:
    Dim W1 As WebViewExtras
W1.executeJavascript(WebView1,"document.getElementById['lst-ib'].value='TEST1';")
W1.executeJavascript(WebView1,"document.forms['tsf'].submit();")
 
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
No sir, for me your previous post link was good, I am not going to use HTTPUTILLS2.

Please just help me finding where is the mistake in my last post code.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Here's an idea...
Without a WebChromeClient the WebView will silently discard any javascript console messages (error messages).
Use WebViewExtras library and it's addWebChromeClient method to add a WebChromeClient to your WebView.
Now run your project again - let your (non-working) javascript execute.
Look in the log - hopefully you'll see some useful javascript console messages logged.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I recall having a similar problem. It was by using
B4X:
getElementById(aFieldID).value=yourValue
in order to set its value in a specific webPage. From what I remember, I changed it to
B4X:
documents.forms[n].aField.value=yourValue
, where forms[n] is the form element, aField is the name of the field (not the id). I never get into why the former didn't work.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
where forms[n] is the form element, aField is the name of the field (not the id)
if you gave form-fields an unique id you can get the object with getElementById; no problem. BUT the field MUST HAVE an id. Not just a NAME.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
if you gave form-fields an unique id you can get the object with getElementById; no problem. BUT the field MUST HAVE an id. Not just a NAME.
I needed access to a site I din't build. I have no idea why the getElementById didn't work, since the id was unique, so I tried the alternative I described, due to lack of time, and luckily it worked.
 
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
Ok, it is ok now, thanks for every one.

It was useful to "addWebChromeClient", it gave me feedback where was the problem. It was just like mentioned above,
the case sensitivity.

Thank you every one.
 
Upvote 0
Top