1

There is a dropdown list in a HTML page:

I want to programmatically change the selected value from the dropdown list using:

webBrowser1.Document.InvokeScript

Executing

$('#year_sel').val('2012').change(); 

in FireBug console works but the same statement does not work when I use

webBrowser1.Document.InvokeScript("$('#year_sel').val('2012').change();")

How can I get that to work using InvokeScript?

Some help would be greatly appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

Here is a written out example which had been working for years:

Dim jsstrings As Object() = {"$('#year_sel').val('2012').change();"}
WebBrowser.Document.InvokeScript("eval", codestring)

It is using javascripts eval plus a parameter.

Nibbels
  • 156
  • 10
0

WebBrowser.Document.InvokeScript expects a JavaScript function name, rather than a script fragment. The function has to be already available in the page's global JavaScript namespace. You can do what you're after by using JavaScript's eval, here is how.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486