0

Hey guys, I'm wondering can someone help me out. I'm using javascript to serialize a search form. It's working.. however, if the user changes the query (backspacing, typing more, etc.) it doesnt update (I'm using a listener) and throws back undefined. How would fix this? http://pastebin.com/edVmQ3si

EDIT: Just to clarify, the listener is working. It's just getting undefined when looking for the values from the code I linked.

Listener just calls the function which executes the code linked.

user596186
  • 579
  • 1
  • 7
  • 16
  • You should post all relevant code here, including the "listener." – Pointy Jan 30 '11 at 23:53
  • Something like http://jsfiddle.net would be nice. – Matt Ball Jan 30 '11 at 23:54
  • Related to [this](http://stackoverflow.com/questions/4843192/get-url-of-page-that-isnt-appearing-in-the-search-bar-google-instant) and [this](http://stackoverflow.com/questions/4843489/javascript-serializing-question). – Raynos Jan 30 '11 at 23:55

1 Answers1

0

Attach it to the keyup event...

var searchInput = $('form[name="gs"]'),
    searchForm = searchInput.closest('form'); // Thanks Matt Ball

var base = searchInput.attr('action');

searchInput.keyup(function() {
    var params = searchForm.serialize();
    var url = base + '?' + params;  
    // Do what you need with url.  
});
alex
  • 479,566
  • 201
  • 878
  • 984
  • 1
    How about just using `.closest()`? – Matt Ball Jan 30 '11 at 23:55
  • @Matt Ball To identify the `form`? Edit: Just read about it - seems to be more appropriate (I thought `closest()` meant it may search siblings as well.) – alex Jan 30 '11 at 23:59