Answers.Body: <p>The widget is <a href="http://select2.github.io/select2/" rel="nofollow">select2 3.5</a>. But you don't need to interact with it directly. Find a selector for the underlying <code>&lt;select&gt;</code> element in the dom, set it's value, and then fire the change event. E.g.</p>
  
  <pre><code>CRM.$(function($) {
    $("#country-1").val(val).change()
  });
  </code></pre>
  
  <p>Note that you should use CiviCRM's copy of jQuery and not the WP copy. So the above code uses <code>CRM.$</code> instead of <code>jQuery</code>. Using the wrong copy of jQuery would make things weird as change events would appear to have no effect, etc.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-25T19:09:32.230Z
Answers.LastActivityDate: 2016-02-25T19:09:32.230Z
Answers.UserDisplayName: Coleman
Body: <p>I want to know how to change the value of those awesome civicrm comboboxes from the code (i have google address search, I need to change the country), see the screenshot. 
  jQuery("#country-1").val(val); document.getElementById('country-1').value = val; don't work
  <a href="https://i.sstatic.net/eifmf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eifmf.png" alt="enter image description here"></a></p>
  
Tags: <wordpress><civimember>
Title: Change civicrm combobox value from the code
ThreadText: # Change civicrm combobox value from the code
  
  (Asked by: username_0 on 2016-02-25)
  
  I want to know how to change the value of those awesome civicrm comboboxes from the code (i have google address search, I need to change the country), see the screenshot.
  jQuery("#country-1").val(val); document.getElementById('country-1').value = val; don't work
  [![enter image description here](https://i.sstatic.net/eifmf.png)](https://i.sstatic.net/eifmf.png)
  
  **Tags:** wordpress, civimember
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-25. Score: 2 | Accepted answer
  
  The widget is [select2 3.5](http://select2.github.io/select2/). But you don't need to interact with it directly. Find a selector for the underlying `<select>` element in the dom, set it's value, and then fire the change event. E.g.
  
  ```
  CRM.$(function($) {
    $("#country-1").val(val).change()
  });
  
  ```
  
  Note that you should use CiviCRM's copy of jQuery and not the WP copy. So the above code uses `CRM.$` instead of `jQuery`. Using the wrong copy of jQuery would make things weird as change events would appear to have no effect, etc.
  
  
  ---
  
  