开发者

Delphi Web Automation How to pass THIS Variable to JavaScript function

HI, I am trying to automate a Combo Box selection and then Screen Scrape the results. But I have a problem firing the Combo Box Change event which is not called when simply changing the selection. The onchange event is set to a JavaScript Function: Something like this:

"AFunction(this,'combochange.asp?AVariable=true&a开发者_运维技巧mp;')"

I am trying to use the HTMLWindow.execScript function to call the JavaScript function (AFunction). The function uses "this" directly

The question: I have a reference to the Combo Box as an IHTMLSelectElement. How do I pass a reference to the Combo Box for the "this" variable in the HTMLWindow.execScript call?

Current Code:

procedure TFormMain.CallComboChange(Doc: IHTMLDocument2; SelectCombo: IHTMLSelectElement);
var
  HTMLWindow: IHTMLWindow2; // parent window of current HTML document
  JSFn: string;             
begin
  HTMLWindow := Doc.parentWindow;
  if not Assigned(HTMLWindow) then
    Exit;
  try
    JSFn := 'AFunction(id_Combo, combochange.asp?AVariable=true&)';  
    HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
  except
    ShowMessage('Opps exception in javascript call');
  end;
end;

I have also tried SelectCombo.OnChange but that does nothing either :(

Thanks.

P.S. this is not hacking. It is simply to automate a time consuming repetitive task. I want to then take the results and feed them into another site (Which I have all working OK)

[Edit] A related question (that might help answer the original one) - JavaScript is an interpreted language so... When I call this function is the function line Interpreted at that point? It must be, Yes? If so I think I just need to go to the "root". Something like:

AFunction(this.form.elements["elementname"], "parameters").

I don't know much JavaScript so is that thinking/syntax along the right lines?


And the answer is:

JSFn := 'AFunction(this.form2.elements["id_Combo"], ''combochange.asp?AVariable=true&'')';  

The clue was "interpreted" so you just present it as you would write a line of JavaScript source.

:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜