-
[RESOLVED] Radio box
I'm having a bit of a problem in a VB script. The assignment is the following: Get a form filled in with pressing 1 button.
In this form I can get everything correct, except for the radiobutton. As html sais, the first option is selected by default. Now when you press a button, ghi should get checked.
The html of this radiobox is the following:
Code:
<input type="radio" class="radio" name="c" value="2" checked="checked">abc
<br>
<input type="radio" class="radio" name="c" value="3">def
<br>
<input type="radio" class="radio" name="c" value="4">ghi
I saw this topic which sais, and made a bit of my own variant to this:
Code:
Public Class Form1
Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
Try
Return DirectCast(WebBrowser1.Document, mshtml.HTMLDocument)
Catch ex As Exception
Return Nothing
End Try
End Function
'SAME AS THE ABOVE FUNCTION, EXCEPT IT GRABS A WEBFORM. I ASSUME HERE THERE IS ONLY 1 FORM
'IF YOU WERE DEALING WITH A PAGE WITH MULTIPLE FORMS, SIMPLY USE ITS INDEX (THEY ARE IN AN ARRAY)
'THIS IS A USEFUL METHOD BECAUSE OFTEN TIMES WHEN MANIPULATING A WEBPAGE, ITS TO GET/SET DATA IN A FORM
Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
Try
If GetCurrentWebDoc.forms.length > 0 Then
Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function
'SET THE RADIO BUTTONS CHECKED. NOTICE THEY ARE BOTH CALLED THE SAME THING, BUT THE INDEX IS DIFFERENT.
Private Sub SetRadioYesChecked()
If x.Checked Then
DirectCast(GetCurrentWebForm.item("c", 3), mshtml.HTMLOptionButtonElement).checked = True
Else
DirectCast(GetCurrentWebForm.item("c", 4), mshtml.HTMLOptionButtonElement).checked = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case True
Case x.Checked, y.Checked : SetRadioYesChecked()
End Select
End Sub
End Class
in this project I have 2 radiobuttons, a webbrowser(which has the html), and a button. When the 1st option(in application) is selected and the button is pressed it should select the 2nd option(in browser), if the 2nd option(in application) is selected, and the button gets pressed it should select the 3rd option(in browser). But when I press the button it sais: 'Object reference not set to an instance of an object.' So why did it work at the other application, but why won't it work with mine?
I'm not asking for a ready script I can copy and paste, just some hints so I can solve it myself. It's a assignment, so I should learn something from it:)
I'm using visual studio if this might make a difference.
Greetings,
Ray
-
Re: Radio box
Saying something like "VB script" is either a typo, a vocabulary problem, or an insult. If this is an assignment then somebody should be advising you: talking wrong is thinking wrong.
There is a scripting language VBScript, but clearly from your code you aren't using that. Instead you are using VB.Net (which is not a scripting language).
In any case you are in the wrong forum. Your question will get better answers in the VB.Net forums here. You are posting in a classic VB forum.
-
Re: Radio box
Well that's just how we call it in dutch, but if you say I have to post it in the VB.net forum I will..
-
Re: Radio box