dcsimg
Results 1 to 6 of 6

Thread: I Can not Change the Value of Web Combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    13

    I Can not Change the Value of Web Combobox

    Hello everybody, I'm trying to change the value of web combobox but it's not changing completely. Actually It's visuality is changes but imagine, it must be black colored but it looks like gray when I try to change it with Visual Basic 6.0. So it's not changing actually, it side will be clear when I post the page. I want to work with API but it hasn't got any API for this job...

    I tried all ways to change it with programming but it does not work. Look at my codes;

    Code:
    WebBrowser1.document.All("mycomboname").Options(0).Value = "0"
    OR

    Code:
    WebBrowser1.document.All("mycomboname").Options(0).Selected = True
    OR

    Code:
    WebBrowser1.Document.Forms(1).All("mycomboname").selectedIndex = "0"
    OR

    Code:
    For Each mycombo In WebBrowser1.Document.getElementsByTagName("select")
     If (mycombo.getAttribute("id") = "mycomboname") Then
      mycombo.value = "0" 'or selectedindex = 0 or 
      Exit For
     End If
    Next
    All I knowledge not works in this combobox. I suppose it's working with a javascript file and this javascript blocks such as this behaviours. When I try it with SendKeys it's working but I can not use SendKeys. (Because as you know we need to foreground program for use SendKeys but mine is not always on foreground.)

    Is there anyway for use SendKeys without foreground? Or anything else for solve this problem?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,881

    Re: I Can not Change the Value of Web Combobox

    what is the html code for the combobox?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    13

    Re: I Can not Change the Value of Web Combobox

    Quote Originally Posted by westconn1 View Post
    what is the html code for the combobox?
    It's it...

    Code:
    <select id="mycombobox" class="mycomboclass">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Not Selected</option>
    </select>

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,901

    Re: I Can not Change the Value of Web Combobox

    Quote Originally Posted by wordtopdf0 View Post
    It's it...

    Code:
    <select id="mycombobox" class="mycomboclass">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Not Selected</option>
    </select>
    Well, if you'd prepare already your initial posting in this way (as shown below in Form_Load),
    you'd make it much easier for potential helpers (to reproduce the problem - and to suggest changes):

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      WebBrowser1.Navigate2 "about:blank"
      Do: DoEvents: Loop Until WebBrowser1.ReadyState = 4 'READYSTATE_COMPLETE
      
      Dim HTML As String
          HTML = HTML & "<select id='mycombobox' class='mycomboclass' value='2'>"
          HTML = HTML & "  <option value='1'>Option 1</option>"
          HTML = HTML & "  <option value='2'>Option 2</option>"
          HTML = HTML & "  <option value='3'>Not Selected</option>"
          HTML = HTML & "</select>"
      WebBrowser1.Document.write HTML
    End Sub
    
    Private Sub Form_Click()
      Static i As Long: i = (i + 1) Mod 3
      WebBrowser1.Document.getElementByID("mycombobox").Value = CStr(i + 1)
    End Sub
    Olaf

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    13

    Re: I Can not Change the Value of Web Combobox

    Quote Originally Posted by Schmidt View Post
    Well, if you'd prepare already your initial posting in this way (as shown below in Form_Load),
    you'd make it much easier for potential helpers (to reproduce the problem - and to suggest changes):

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      WebBrowser1.Navigate2 "about:blank"
      Do: DoEvents: Loop Until WebBrowser1.ReadyState = 4 'READYSTATE_COMPLETE
      
      Dim HTML As String
          HTML = HTML & "<select id='mycombobox' class='mycomboclass' value='2'>"
          HTML = HTML & "  <option value='1'>Option 1</option>"
          HTML = HTML & "  <option value='2'>Option 2</option>"
          HTML = HTML & "  <option value='3'>Not Selected</option>"
          HTML = HTML & "</select>"
      WebBrowser1.Document.write HTML
    End Sub
    
    Private Sub Form_Click()
      Static i As Long: i = (i + 1) Mod 3
      WebBrowser1.Document.getElementByID("mycombobox").Value = CStr(i + 1)
    End Sub
    Olaf
    Thanks for your patience. as I said .value command not working. I guess some javascript codes blocking this situation.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,881

    Re: I Can not Change the Value of Web Combobox

    I guess some javascript codes blocking this situation.
    post a link to the webpage?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width