Solved

Check a radio button in the web browser control

Posted on 2010-09-24
10
2,939 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

831 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