Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check a radio button in the web browser control

Posted on 2010-09-24
10
Medium Priority
?
3,293 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
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.

 
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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 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…
Suggested Courses

636 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