Jump to content

javascript onChange


ame1011
 Share

Recommended Posts

I just wanted to know how to invoke a javascript onchange on a select box.

The HTML code (of the frame that the select box is located in) looks like this:

CODE

<select name="DropDownList2" onchange="__doPostBack('DropDownList2','')" language="javascript" id="DropDownList2">

<option selected="selected" value="1">1</option>

<option value="2">2</option>

</select>/2

My code looks like this so far:

$oMiddleContent = _IEFrameGetObjByName($oIE, "middle_content")
    $numPages = traverseElements($oMiddleContent)
    
    ;if multiple pages
    if $numPages > 1 Then
        for $u = 2 to $numPages
            ;visit new page
            $dropdown = _IEGetObjById($oMiddleContent, "DropDownList2")
            $dropdown.value=$u
            _IELoadWait($oIE)
            $oMiddleContent = _IEFrameGetObjByName($oIE, "middle_content")
            $numPages = traverseElements($oMiddleContent)
        Next
    EndIf

this however doesn't work. I can't just simply change the value of the select box. The above select box is also not in a form thus I can't just submit a form. Additionally, the URL doesn't change when the second page is loaded so I can't pass info through that.

Any help is appreciated, thanks in advance

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

#include <IE.au3>

_IEFormElementOptionselect ( ByRef $o_object, $s_string [, $f_select = 1 [, $s_mode = "byValue" [, $f_fireEvent = 1]]] )

Parameters

$o_object Form Element Object of type "Select Option"

$s_string Value used to match element - treatment based on $s_mode

$f_select Optional: specifies whether element should be selected or deselected

-1 = Return selected state

0 = Deselect the element

1 = (Default) Select the element

$s_mode Optional: specifies search mode

byValue = (Default) value of the option you wish to select

byText = text of the option you wish to select

byIndex = 0-based index of option you wish to select

$f_fireEvent Optional: specifies whether to fire onchange and onclick events after changing value

0 = do not fire onchange or onclick event after setting value

1 = (Default) fire onchange and onclick events after setting value

Link to comment
Share on other sites

ah, lol oops...

I usually only use the _IE functions to open, close and collect collections of objects and I prefer to do everything else directly with the DOM. I totally missed that function, thanks!

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

new problem:

$oMiddleContent = _IEFrameGetObjByName($oIE, "middle_content")
    $numPages = traverseElements($oMiddleContent)
    
    ;if multiple pages
    if $numPages > 1 Then
        for $u = 2 to $numPages
            ;visit new page
            $dropdown = _IEGetObjById($oMiddleContent, "DropDownList2")
            _IEFormElementOptionselect($dropdown, $u)
            _IELoadWait($oIE)
            $oMiddleContent = _IEFrameGetObjByName($oIE, "middle_content")
            $numPages = traverseElements($oMiddleContent)
        Next
    EndIf

the script doesn't wait for the page to change, it just moves onto the next item. I see the select box change to 2, but the _IELoadWait doesn;t seem to be executing

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

Try

_IELoadWait($oMiddleContent)

_IELoadWait($oIE)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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...