Link to home
Start Free TrialLog in
Avatar of stuayre
stuayre

asked on

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

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

hi

some useful links for u

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

by
kumaresan
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
ASKER CERTIFIED SOLUTION
Avatar of stuayre
stuayre

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stuayre
stuayre

ASKER

this one works