Solved

Check a radio button in the web browser control

Posted on 2010-09-24
10
2,833 Views
Last Modified: 2013-12-25
I am having trouble making to check a radio button in the web browser control. The HTML code is below with the 2 radio buttons/options.

                             <input type="radio" name="visibility" id="visibility" value="0" /> Yes
                              <input type="radio" name="visibility" value="1" checked="checked" /> No


USING: VB 2008
0
Comment
Question by:battleweb
  • 4
  • 4
  • 2
10 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33756336
Are you not making use of asp.net?

in html, to set a value checked surely you just specify checked?

 <input type="radio" name="visibility" value="1" checked /> No
0
 

Author Comment

by:battleweb
ID: 33756365
huh?

<input type="radio" name="visibility" id="visibility" value="0" /> Yes
<input type="radio" name="visibility" value="1" checked="checked" /> No

is part of the source for the web page, I am trying to change the radio button selected using Visual Basic 2008 remotely, I am not trying to alter the source for the page.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33756474
Try something like this...
WebBrowser1.Document.GetElementById("visibility").SetAttribute("checked", "1") '// Yes

WebBrowser1.Document.GetElementById("visibility").SetAttribute("checked", "0") '// No

Open in new window

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33756600
ok, got confused. just a thought why would you be using a webbrower control. Is this on a application?
0
 

Author Comment

by:battleweb
ID: 33756637
eql1044 - that almost does it, but the code above can only check the first radio if it isn't already checked - this is kind of my problem, there are 2 radio buttons, both named "visibility" but each has a different value (the first is 0 and the second is 1) - how do I control both?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:battleweb
ID: 33756642
rockiroads - yes, which is why VB 2008 is being used.
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 33756734
Okay I see what your saying.. You will probrably need to get a collection of HtmlElements so you can play with both of them instead of it only returning the first one..
Here is my test example which seems to work but to be honest, I'm not sure if there is a better way of filtering the elements besides filtering by Input tag and checking for "visibility" name.

Public Class Form1

    Dim list As New List(Of HtmlElement)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        WebBrowser1.Navigate("C:\Users\username\Documents\test.html")

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        list.Clear()

        Dim hElemCol As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")

        For Each elem As HtmlElement In hElemCol

            If elem.Name.Contains("visibility") Then

                list.Add(elem)

            End If

        Next

        Dim yes As HtmlElement = list.Item(0)

        Dim no As HtmlElement = list.Item(1)

        'yes.SetAttribute("checked", "1")

        'no.SetAttribute("checked", "0")

    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:battleweb
ID: 33756860
eql1044 - with just a little tweaking, that works for me...Thanks.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33758637
Yeah... Actually the filtering was right there in plain site I just missed it :(  If you haven't already I would change it to this..
Dim checkboxes As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input").GetElementsByName("visibility")

Debug.Print(checkboxes.Count)

Open in new window

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33758651
LOL... plain *sight
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now