Jump to content

How do I select an option from a dropdown in IE if it is updated by another select by AJAX?


Afaan
 Share

Recommended Posts

Using _IEFormElementOptionSelect I would imagine. <shrug>

You asked a question and I answered it. If you want assistance with a specific website, then you will need to provide more information, such as:

  • The site name / URL
  • Your code showing what you have tried thus far

If the site isn't open to the public, then it would be good if you found an example of one that is so that we can use it to test and provide you with a working solution.

Link to comment
Share on other sites

_IEFormElementOptionSelect works fine with regular <select>s. I use it to set the first select which triggers an ajax request which in turn gets the options for the second select. If I call _IEFormElementOptionSelect on that, it just does nothing. Is there any way that I can wait for the second select to load the options first before attempting to select one?

My code so far:

Func WaitForSelect($argForm, $argSelect, $argOptVal)
    While 1
        $options = _IETagNameAllGetCollection(_IEFormElementGetObjByName($argForm, $argSelect))
        For $opt In $options
            Sleep(100)
            If $opt.value = $argOptVal Then
                _IEFormElementOptionSelect(_IEFormElementGetObjByName($argForm, $argSelect), $argOptVal)
                If _IEFormElementGetObjByName($argForm, $argSelect).value = $argOptVal Then
                    ExitLoop 2
                EndIf
            EndIf
        Next
    WEnd 
EndFunc

It works sometimes, sometimes it doesn't. I need something reliable.

Thanks!

Link to comment
Share on other sites

You are making multiple calls to _IEFormElementGetObjByName. Is there a reason that you can't call it once and then use the object reference for subsequent calls, ie:

$oSelect = _IEFormElementGetObjByName($argForm, $argSelect)

$options = _IETagNameAllGetCollection($oSelect)

Also, please provide a better description than "doesn't work". What happens? Does it loop forever in the function? Or what?

Link to comment
Share on other sites

I wonder if something like this would work better?

Func WaitForSelect($argForm, $argSelect, $argOptVal, $argDelay = 500)
    Local $oSelect, $oOptions, $nCnt1, $nCnt2
    
    $oSelect = _IEFormElementGetObjByName($argForm, $argSelect)
    
    While 1
        $oOptions = _IETagNameAllGetCollection($oSelect)
        $nCnt1 = @extended
        
        Sleep($argDelay)
        
        $oOptions = _IETagNameAllGetCollection($oSelect)
        $nCnt2 = @extended
        
        If $nCnt1 = $nCnt2 Then
            _IEFormElementOptionSelect($oSelect, $argOptVal)
            ExitLoop
        EndIf
    WEnd 
EndFunc

 

Link to comment
Share on other sites

I found a work-around which seems to work fine.

Func SetAjaxSelect($argForm, $argSelect, $argOptVal)
    $theSelect = _IEFormElementGetObjByName($argForm, $argSelect)
    $options = 0
    Do
        $options = _IETagNameAllGetCollection($theSelect)
        Sleep(50)
    Until IsObj($options)
    For $opt in $options
        If $opt.value = $argOptVal Then
            Sleep(200)
            _IEFormElementOptionSelect($theSelect, $argOptVal)
            Return
        EndIf
    Next
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...