0

I am using the following with an address picker.

HTML

<form>
<input id="searchByLoc" type='checkbox' >
<input id="searchQuery" type='text' >
<input type="submit' value="search">
</form>

JQuery:

$('#searchByLoc:checkbox ').live('change', function(){
    if($(this).is(':checked')){
        var addresspicker=$(this).addresspicker();//alert('checked');
    } else {
         //I want to un initialize the addresspicker() on the input field
         var addresspicker=die($(this).addresspicker());//alert('un-checked');
    }
});

I am having some trouble with the ELSE part above. If the check box is unchecked, how can I stop the initialization so that no location is suggested?

aVC
  • 2,056
  • 2
  • 19
  • 44
  • 1
    I'm confused, isn't just remove the else? –  Jan 22 '13 at 18:08
  • Well, no. bcz the input field is intended to be used for both search by name as well as location. so, if a search is done for location and then a search for name is about to be done, I would like to have no location suggestions. – aVC Jan 22 '13 at 18:10
  • I don't think that unbinding the change event is what you want, but instead handle in your `adresspicker()` if it's checked or not... –  Jan 22 '13 at 18:13
  • yeah exactly. its a plugin i forked, and not sure how to undo the function working on the input field – aVC Jan 22 '13 at 18:14
  • So give us more info. Who's the plugin? What adresspicker do? –  Jan 22 '13 at 18:18
  • @SérgioMichels http://xilinus.com/jquery-addresspicker/demos/index.html – aVC Jan 22 '13 at 18:20
  • 1
    Looking at the [jQuery UI docs](http://wiki.jqueryui.com/w/page/12138135/Widget%20factory), it looks like you want to `destroy` it. `.addresspicker("destroy")`. Not sure if that's handled by the base widget or if the plugin has to manually define its own `destroy` method. – Chris Jan 22 '13 at 18:26

1 Answers1

2

Use unbind() function of jquery. It will remove the event. jquery bind

You can see this post also for best usage best way to remove events

below jquery 1.7

$('#yourDomElement').unbind('click');

jquery 1.7+

$('#yourDomElement').off('click');
Community
  • 1
  • 1
Ravi Gadag
  • 15,331
  • 5
  • 53
  • 83