c# webbrowser click radio button in a form
<p>I am using webbrowser element in my code to automate some stuff. I am loading a form in this webbrowser, which contains several radiobutton in. My purpose is just to select one of the radi buttons. However, in the html code, there is a JS code which changes the form action target depending on the selected radio button. So if I use, </p>

<pre><code>webBrowser1.Document.GetElementById("chicken").SetAttribute("checked", "checked");
</code></pre>

<p>it selects the radio button that I want but just that. I mean it doesn't trigger the JS code. In this JS Code, it also submits the page, so my code above only selects the radio button and calls the same page. How can I solve this?</p>

<p>Form tag is like the following:</p>

<pre><code>&lt;form id="choose_dept" method="POST" action="/place/"&gt;
</code></pre>

<p>JS code is like this:</p>

<pre><code>&lt;script type="text/javascript"&gt;
&lt;!--
$("#choose_dept").change(function(){
  $("#choose_dept").attr('action', '/place/' + ('input[name=department]:checked').val()
   + '/' );
  this.submit();
});
</code></pre>

<p>-->
  </p>

<p>Last edit:</p>

<pre><code>        String sc = @"$(document).ready(function(){" +
        "$(\"input:radio[name=department]\").change(function() {" +
        "$(\"#choose_dept\").attr('action','place/'+$(this).val());" +
        "$(\"#choose_dept\").submit();" +
        "});" +
        "});";

        HtmlElement headElem = (HtmlElement)webBrowser1.Document.GetElementsByTagName("head")[0];
        HtmlElement scriptElem = (HtmlElement)webBrowser1.Document.CreateElement("script");
        IHTMLScriptElement elem = (IHTMLScriptElement)scriptElem.DomElement;
        elem.text = sc;
        headElem.AppendChild(scriptElem);

        webBrowser1.Document.GetElementById("chicken").SetAttribute("checked", "checked");
        webBrowser1.Document.InvokeScript("ready()");
</code></pre>
