Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with deferred promise stuff

    I am trying to work around a situation where i cannot change the order of code on my page.
    so i would like to use the promise() feature in jquery.

    I have some stuff in jsbin here
    http://jsbin.com/EqAyIvo/3
    http://jsbin.com/EqAyIvo/3/edit

    Code:
    // i cannot change the order of these functions.
    // how can i make the first function at the top of my code always occur last?
    // e.g. select an option from second drop down
    // now change the first select list to anything.
    // it will change the second select to the top option
    // but I want my first call to on.('change') to happen last.
    
    
    //i want this to occur last
    $('#selDealers').on('change', function(){
      console.log('dealer changed');
      //set option to the top default one
      $("#selOrderType").val( 'ZAVR' ).attr('selected',true);
      $("#selOrderType").change();
    });
    
    //this currently occurs last (but i don't want it to)
    $('#selDealers').on('change', function(){
      console.log('dealer changed');
      //set option to the top default one
      $("#selOrderType").val( false ).attr('selected',true);
      $("#selOrderType").change();
    });
    
    //this select list gets changed when first select is changed
    $('#selOrderType').on('change', function(){
      console.log('order type changed');
    
    });
    i have no idea how promise works

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    if you wouldn’t use jQuery, it would be easy. define the first a bubbling and the second a capturing event handler (though that has problems with older IEs).

    i have no idea how promise works
    in very short words, a Promise is a yet unknown value that is given a success handler and an error handler, of which that either is executed once the value is created or its creation failed. you could say it’s a little bit like Schrödinger’s Cat. it’s more about asynchronity than events.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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