-1

I am new to jQuery $.When. I am trying to fill a textbox after another textbox be filling

<script>
         var search;
         $.when( search= $("#newhiddenfield").val()).then(myFunc(search)) 

            (function teste(search) {                
                $('.gsc-input').val(search);
                $('.gsc-search-button').click();
            })();  

</script>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mario
  • 241
  • 1
  • 2
  • 6
  • 1
    You are confusing concepts. $.When has nothing to do with what you are trying to achieve. This pattern is used for different purposes. Maybe you need event listeners: http://jsfiddle.net/8ok26wkv/ – dfsq Oct 22 '14 at 15:02
  • 1
    Maybe first of all you should understand `$.when()` and then ask how to do it in javascript..? Can you explain what you're trying to achieve..? – T J Oct 22 '14 at 15:09
  • $.when does not do what you think it does. It will not listen for a variable or input to change, all it does is combine multiple promise objects into one, which has nothing to do with what you appear to be trying to do. – Kevin B Oct 22 '14 at 15:21

1 Answers1

0

$.when in jquery works with jquery's Deferred object (for async behavior).

In your case, DOM operations does not require when. You can just write:

var search = $("#newhiddenfield").val();

$('.gsc-input').val(search);
$('.gsc-search-button').click();
Mifeng
  • 1,525
  • 15
  • 26