[RESOLVED] A different problem with Webbrowser control
I'll explain my situation.
I have a webbrowser control in my form using which I fill a form a submit data. The comment submission form is supposed to have 3 text boxes but sometimes there could be 4. So I need to know the exact number before trying to fill the form. Also the issue is there could be more than one form in this page and therefore I can't call it like form(0) or form(1) as the index can vary. But the good thing is the id of the form to be filled is always the same. So I can call it with getelementbyid("postform").
So my question is how can I count the no.of text boxes belonging to the form with id "postform"?
Re: A different problem with Webbrowser control
I'm not sure how to do it with the webbrowser control, but it do it via javascript, you would do:
Code:
function CountTexts()
{
var iTexts = 0;
for( i = 0; i < document.getElementById( "postform" ).elements.length; i++ )
{
if( document.getElementById( "postform" ).elements[ i ].type == 'text' )
{
iTexts++;
}
}
return( iTexts );
}
Hopefully this helps in some way. If you can loop the elements and count their type in VB, this should get you the number of input type=text.
Re: A different problem with Webbrowser control
Thanks Hobo. Let me try to convert it to VB.
Re: A different problem with Webbrowser control
I think this should do:
VB Code:
Private Sub Command1_Click()
Dim oElement
Dim n As Long
For Each oElement In WebBrowser1.Document.getElementById("postform").Elements
If oElement.Type = "text" Then
n = n + 1
End If
Next
MsgBox "No. of text fields: " & n
End Sub
Pradeep :)
Re: A different problem with Webbrowser control
Thank you Pradeep. It really worked.
Also many thanks to Hobo for giving me something to start with.