Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Auto-complete

Post Reply
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Auto-complete

Post 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';
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Auto-complete

Post by salvadordf »

Hi,

Try modifying the value property in an INPUT element.
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: Auto-complete

Post 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.
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Auto-complete

Post 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.
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: Auto-complete

Post 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
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: Auto-complete

Post 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.
:?
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Auto-complete

Post 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
Laertes
Posts: 29
Joined: Fri Apr 27, 2018 1:27 pm

Re: Auto-complete

Post by Laertes »

There would be a simpler way to populate fields from the site like this example:

Image



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?
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Auto-complete

Post by salvadordf »

Laertes wrote: Fri Jun 22, 2018 9:20 pm Does the CEF4 project source have fill-in examples?
No, sorry.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: Auto-complete

Post 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:

Image



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.
Post Reply