views:

366

answers:

2

Hi,

I can do most things I need to with mshtml, but I'm a bit stuck with how to set a checkbox input element to "checked". Here's the situation...

IHTMLElementCollection inputElements = (IHTMLElementCollection)doc.all.tags("input");
foreach (IHTMLElement el in inputElements)
{
    string elementHtml = el.outerHTML;
    string termsOfServiceIdentifier = "id=chkUTOS_ver2";

    //  select the Terms of Service checkbox
    if (elementHtml.Contains(termsOfServiceIdentifier)) 
    {
        HTMLInputElement chkTOS = (HTMLInputElement)el;
        chkTOS.@checked = true;  //  that's the solution. Thanks Wayne.
     }
     else
     {
        //  do nothing - we're not interested in this element
     }
}

Thanks in advance for any help!

Gregg

A: 

In plain JavaScript, checkbox elements have a checked property. So [in plain JavaScript] you might write:

document.getElementById("myCheckbox").checked = true;

I don't know .NET or whatever you're using there, but they may do it in a similar way.

Steve

Steve Harrison
Thanks for the help. BTW It's C#.
Gregg Cleland
+3  A: 

HTMLInputElement exposes the Checked property as a Boolean

Jeremy
I must have messed something up before, 'cause it wasn't in Intellisense. Now it sure is. Cheers Wayne!
Gregg Cleland