Page 1 of 1
Auto-complete
Posted: Fri Apr 27, 2018 1:38 pm
by Laertes
Good Morning !
I'm new to the component, I'd like to know how to complete a field on a web page. Thank you very much in advance.
I tried to use it this way but it did not succeed.
document.getElementById('body').value = 'testing123';
Re: Auto-complete
Posted: Fri Apr 27, 2018 2:12 pm
by salvadordf
Hi,
Try modifying the value property in an INPUT element.
Re: Auto-complete
Posted: Fri Apr 27, 2018 5:11 pm
by Laertes
Hi salvadordf !
Thanks for the answer ! But I could not solve it, see my code as it was
Chromium1.Browser.MainFrame.ExecuteJavaScript ('document.getElementsByid ("custom-message"). Input = 123456789;');
Nothing happens.
Re: Auto-complete
Posted: Fri Apr 27, 2018 6:33 pm
by salvadordf
Let's say that your web page has an INPUT element with an ID attribute set to "myid" like this :
Code: Select all
<html>
<body>
<input id="myid" type="text">
</body>
</html>
Then you would have to use this :
Code: Select all
document.getElementById("myid").value = "My new value";
There are many more JavaScript examples if you search "
javascript how to change input value" in google.
Re: Auto-complete
Posted: Fri Apr 27, 2018 7:26 pm
by Laertes
I got results doing this way
Chromium1.Browser.MainFrame.ExecuteJavaScript ('document.getElementById (' 'custom-message' '). SetRangeText (' 'New Value' ')', Chromium1.browser.MainFrame.GetURL (), 0);
Thank you very much
Re: Auto-complete
Posted: Mon May 28, 2018 9:23 pm
by Laertes
Hello !
I was able to fill the field with this code
Chromium1.Browser.MainFrame. ExecuteJavaScript ('document.getElementById (' 'custom-message' '). SetRangeText (' 'New Value' '), Chromium1.browser.MainFrame. GetURL (), 0);
I'm getting the data from a memo, but when the memo has more than one line, when I insert the next line, I'm throwing the text down. That is, it is ending with the text like this:
line 2,
line 1,
line 0.
The correct would be:
line 0,
line 1,
line 2 ...
You may have to place the mouse cursor just after the first line, so when you insert the next line.

Re: Auto-complete
Posted: Tue May 29, 2018 8:52 am
by salvadordf
CEF4Delphi is just a Delphi wrapper around the CEF3 API.
CEF3 includes Chromium but CEF4Delphi can't modify how some Chromium's features work.
This is purely a JavaScript question. If you search for
"javascript how to add line to textarea" in
Google you will find solutions like this one :
https://stackoverflow.com/questions/424 ... javascript
Re: Auto-complete
Posted: Fri Jun 22, 2018 9:20 pm
by Laertes
There would be a simpler way to populate fields from the site like this example:
I tried this code but I did not succeed.
Code: Select all
Chromium1.Browser.MainFrame. ExecuteJavaScript ('document.getElementById("text8").SetRangeText("7489"))',Chromium1.browser.MainFrame. GetURL (), 0);
Does the CEF4 project source have fill-in examples?
Re: Auto-complete
Posted: Sat Jun 23, 2018 6:12 am
by salvadordf
Laertes wrote: Fri Jun 22, 2018 9:20 pm
Does the CEF4 project source have fill-in examples?
No, sorry.
Re: Auto-complete
Posted: Mon Oct 15, 2018 12:36 pm
by coater
Laertes wrote: Fri Jun 22, 2018 9:20 pm
There would be a simpler way to populate fields from the site like this example:
I tried this code but I did not succeed.
Code: Select all
Chromium1.Browser.MainFrame. ExecuteJavaScript ('document.getElementById("text8").SetRangeText("7489"))',Chromium1.browser.MainFrame. GetURL (), 0);
Does the CEF4 project source have fill-in examples?
you can use
getElementsByName();
-------------------
var x = getElementsByName("text8")[0];
if (x != null )
{
alert(x.innerHTML);
x.value=" ";
}
only <IE9 ID has been seen as same as name in an element.