Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Programmatically force to search #5

BlaM opened this Issue · 1 comment

1 participant


Hey, what about a challenge? :)

What I need to do is to have an option to trigger a search from my program code - followed by selecting an item from the list.


The list contains the items

  • 1. peach
  • 2. pineapple
  • 3. passiflora

The user clicks on a button somewhere in the page. That button should trigger an event and force the list to be set to "apple"

ajaxChosen would need to do an ajax request to fetch the id and the item "apple", modify the list and then select the specified item.

I will try to solve that myself now, but I'll do it in JavaScript. No time to learn CoffeeScript now.


For everybody interested: here is my jQuery code to force the list to include a given item. It's based on my special case where #chzn is the chosen box:

var setBox = function(id) {
    var $opt = $('#chzn option[value="' + id+ '"]');
    if ($opt.length == 0) {
        // Need to load first
            'url': 'ajax.asp',
            'data': {"id": id},
            success: function(data, t, x) {
                if (data.length == 1) {
                    var $opt = $('<option value="' + data[0]['id'] + '">').html(data[0]['text']);
                } else {
                    // Deal with "not found" state.
    } else {
        // Already exists

This code exists outside the ajax-chosen environment but might be worth to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.