[CLOSED] ComboBox - How do I expand a ComboBox in Javascript?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] ComboBox - How do I expand a ComboBox in Javascript?

    I have a little bit of a problem understanding how you reference Controls in Javascript.

    If I have a Javascript-function without any parameters it seems like "this" references the Control that the listener who fired the event is attached to.

    So if I have a JS-function like this:

    function checkValueArea() {
                var id = this.getValue();
    }
    that gets called from a ComboBox like this:

    <ext:ComboBox runat="server" EmptyText="Inget område valt"
                            ID="Field_Address_ComboBox_Area">
                            <Store>
                                <ext:Store ID="Field_Address_Store_Area" runat="server" AutoLoad="false" OnRefreshData="Field_Address_Store_Area_Refresh">
                                    <Proxy>
                                        <ext:PageProxy />
                                    </Proxy>
                                    <Reader>
                                        <ext:ArrayReader>
                                            <Fields>
                                                <ext:RecordField Name="AreaId" />
                                                <ext:RecordField Name="AreaName" />
                                            </Fields>
                                        </ext:ArrayReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Listeners>
                                <Blur Fn="checkValueArea" />
                            </Listeners>
                        </ext:ComboBox>
    i get the correct value in "id".

    But if the JS-function looks like this:

    function checkValueArea(testVar) {
                var id = this.getValue();
    }
    I get an javascript error saying that

    Uncaught TypeError: Object [object DOMWindow] has no method 'getValue'
    I'd appreciate a few words on this =)

    Thx.
    Last edited by Daniil; Apr 04, 2011 at 9:01 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Do you change .Fn to .Handler in the second case? If so, the scope (iow, 'this' reference) is not the control. Default scope of JavaScript function is 'window' object. So, the 'window' object doesn't have .getValue() method.

    You could type something like "javascript scope function" in google.com or others to get more information about a scope of function in JavaScript.
  3. #3
    Hi Daniil,

    no actually I still use the "Fn"-thing. So the only thing changed is the Javascript function as above, and adding the parameter like this:

    <Listeners>
         <Blur Fn="checkValueArea(123)" />
    </Listeners>
  4. #4
    <Listeners>
         <Blur Fn="checkValueArea(123)" />
    </Listeners>
    This code should not work. It causes JavaScript error.

    To pass any additional arguments to the function, please use .Handler.
    var onBlur = function (field, param1, param2) {
        
    }
    
    <Blur Handler="onBlur(this, param1, param2);" />
  5. #5
    But if I do the "searching(123)" as staed above, I get the error:

    Uncaught TypeError: Object [object DOMWindow] has no method 'getValue'
    So all of a sudden the "this" means window, and the only thing I changed was the parameter.

    I will in the future keep in mind that if sending parameters, I should use Handler instead.
  6. #6
    Im not reallyt sure how its solved this thread, so I have to ask again =)

    if I do a

    <Listeners>
         <Blur Fn="checkValueArea" />
    </Listeners>
    and calling this javascript method:

    function checkValueArea() {
                var id = this.getValue();
    }
    it works - the "id" get the correct value. But If I call the exact same Javascript method like this:

    <Listeners>
         <Blur Handler="checkValueArea()" />
    </Listeners>
    I get the error as described above:

    Uncaught TypeError: Object [object DOMWindow] has no method 'getValue'
    Maybe you did answer it, in which case I didnt get it.

    Is it meant to be like this, and why?
  7. #7
    I thought it's solved.

    Yes, generally, I showed how to solve the problem in my previous post. Please review.

    To pass any additional arguments to the function, please use .Handler.
    var onBlur = function (field, param1, param2) {
         
    }
     
    <Blur Handler="onBlur(this, param1, param2);" />
    Just use the "field" function's argument instead of this reference.

    The answer how the error occurs is in the second post of this thread.
  8. #8
    Hi,

    I suggest to read about scope in javascript.
    Please review the following article
    http://www.digital-web.com/articles/...in_javascript/
  9. #9
    Ok, it seem to work now.

    Odd, I must have made som error before with the Handler since I was under the impression that it didnt work.

    Sorry. you can close it now.

    Regards
  10. #10
    Sorry, I acutally messed up the question a bit.

    As the title goes; how do I expand a ComboBox in Javascript?

    I tried
    <Focus Handler="this.expand();" />
    but that didnt work (Cannot call method 'setWidth' of undefined).

    I searched the forum but didnt find anything. I also searched the net, didnt find much.

    can it be done? =)
    Last edited by Daniil; Apr 04, 2011 at 1:14 PM. Reason: Please use [CODE] tags
Page 1 of 2 12 LastLast

Similar Threads

  1. combobox expand on store refresh
    By ascsolutions in forum 1.x Help
    Replies: 0
    Last Post: Jun 19, 2012, 1:38 PM
  2. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  3. Expand combobox list automatically.
    By rahesh in forum 1.x Help
    Replies: 0
    Last Post: Nov 11, 2011, 11:12 AM
  4. Replies: 1
    Last Post: Apr 17, 2011, 1:21 PM
  5. [CLOSED] Desktop | Composite/MultiField | ComboBox does not expand
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 26, 2010, 7:34 AM

Tags for this Thread

Posting Permissions