Results 1 to 5 of 5

Thread: [RESOLVED] A different problem with Webbrowser control

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    56

    Thumbs up [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"?
    Last edited by Inman; Nov 29th, 2006 at 02:07 PM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    56

    Re: A different problem with Webbrowser control

    Thanks Hobo. Let me try to convert it to VB.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: A different problem with Webbrowser control

    I think this should do:

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim oElement
    3.     Dim n As Long
    4.     For Each oElement In WebBrowser1.Document.getElementById("postform").Elements
    5.         If oElement.Type = "text" Then
    6.             n = n + 1
    7.         End If
    8.     Next
    9.     MsgBox "No. of text fields: " & n
    10.  
    11. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    56

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width