• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2236
  • Last Modified:

How do I fire an onChnage even in a twebbrowser - Delphi

Hi,

I'm loading a webpage into a twebbrowser in delphi

the webpage contains a dropdown menu, i can select the menu item i want but it wont fire the OnChange event.

I've tried to use the HTMLWindow.execScript('yourfunctioname()', 'JavaScript');  method

but it always throws back errors (delphi could not complete the operation due to error 80020101) I think it might be an AJAX issue.

I was trying to get around it by using the OleVariant(yourIHTMLElement).FireEvent('onchange') ; method but im not sure how to use it, can anyone provide an example?

the only other way would be to simulate a mouse click on the dropdown?


here's the dropdown im trying to change:


many thanks

Stu

<select align="left" id="carrierNameDropDown_UNSHIPPEDITEMS" onChange="MYO.ES.OtherCarrierToggle (this, 'UNSHIPPEDITEMS' )">
          <option value="0"  selected="1" >Select</option>
              <option value="Chronopost"  >Chronopost</option>
              <option value="City Link"  >City Link</option>
              <option value="DHL"  >DHL</option>
              <option value="DPD"  >DPD</option>
              <option value="Deutsche Post"  >Deutsche Post</option>
              <option value="Fastway"  >Fastway</option>
              <option value="FedEx"  >FedEx</option>
              <option value="GLS"  >GLS</option>
              <option value="GO!"  >GO!</option>
              <option value="Hermes Logistik Gruppe"  >Hermes Logistik Gruppe</option>
              <option value="La Poste"  >La Poste</option>
              <option value="Parcelforce"  >Parcelforce</option>
              <option value="Parcelnet"  >Parcelnet</option>
              <option value="Poste Italiane"  >Poste Italiane</option>
              <option value="Royal Mail"  >Royal Mail</option>
              <option value="SDA"  >SDA</option>
              <option value="Smartmail"  >Smartmail</option>
              <option value="TNT"  >TNT</option>
              <option value="Target"  >Target</option>
              <option value="UPS"  >UPS</option>
              <option value="Yodel"  >Yodel</option>

          <option value="Other">
              Specify carrier:
          </option>
        </select>

Open in new window

1
stuayre
Asked:
stuayre
  • 3
  • 2
1 Solution
 
kumaresan2011Commented:
hi

some solutions for you

try it

by
kumaresan
uses 
  MSHTML;

procedure TBrowserPageIE.Test;
var
  doc : IHTMLDocument3;
  el  : IHTMLElement;
  v   : OleVariant;
begin
  if FBrowser.Document <> nil then begin
    if FBrowser.Document.QueryInterface(IHTMLDocument3,doc) = S_OK then begin
      el := doc.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');

      if el <> nil then begin
        (el as IHTMLSelectElement).value := 'UPS';
        (el as IHTMLElement3).FireEvent('onchange', v);
      end;
    end;
  end;
end;

Open in new window

0
 
kumaresan2011Commented:
hi

some useful links for u

http://www.delphidabbler.com/articles?article=21

by
kumaresan
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kumaresan2011Commented:
hi

look this, it may be help ful to you

procedure TForm1.Button3Click(Sender: TObject);
var  Doc:        IHTMLDocument2;
     HTMLWindow: IHTMLWindow2; // parent window of current HTML document
begin

  with form1 do
  begin
     Doc := WebBrowser1.Document as IHTMLDocument2;
     if not Assigned(Doc) then Exit;
     HTMLWindow := Doc.parentWindow;
     if not Assigned(HTMLWindow) then Exit;
     HTMLWindow.execScript('_myoES_OtherCarrierToggle(changecolour)', 'Javascript');
  end;

end;
Unit1.dfm
Unit1.pas
Article21.dpr
FmDemo.dfm
FmDemo.pas
Test.html
0
 
stuayreAuthor Commented:
here's the answer:

if EmbeddedWB1.Document <> nil then begin
if EmbeddedWB1.Document.QueryInterface(IHTMLDocument3,docb) = S_OK then begin
elb := docb.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');
if elb <> nil then begin
(elb as IHTMLSelectElement).value := 'Parcelforce';
OleVariant (elb as IHTMLElement). FireEvent ('onchange');
end;

Open in new window

0
 
stuayreAuthor Commented:
this one works
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now