?
Solved

Check a radio button in the web browser control

Posted on 2010-09-24
10
Medium Priority
?
3,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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