Question

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

Was it helpful?

Solution

HTMLInputElement exposes the Checked property as a Boolean

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top