title: Uncaught ReferenceError: onchange function is not defined (wordpress)
body: <p>I am trying to insert a dropdown list of layers to display the layer selected in a map in wordpress using Openlayers tool. But i get this error when i tried to choose from the drpdown list :</p>
  
  <pre><code>Uncaught ReferenceError: update is not defined
      at HTMLSelectElement.onchange ((index):226)
  </code></pre>
  
  <p>My script : </p>
  
  <pre><code>var geojsonFormat = new ol.format.GeoJSON();
  
  var vectorSource = new ol.source.Vector({
    loader: function(extent, resolution, projection) {
      var url = "http://localhost:8080/geoserver/opengeo/ows?service=WFS&amp;" +
          "version=2.0.0&amp;request=GetFeature&amp;typename=opengeo:arbousiers0&amp;CQL_FILTER=code_espec='Arteherb'"+
          "&amp;outputFormat=text/javascript&amp;format_options=callback:loadFeatures"+
          "&amp;srsname=EPSG:3857";
  
      $.ajax({url: url, dataType: 'jsonp', jsonp: false});
    },
    strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
      maxZoom: 19
  
    }))
  
  });
  window.loadFeatures = function(response) {
    vectorSource.addFeatures(geojsonFormat.readFeatures(response));
  };
  
  function update() {
    vectorSource.clear(true);
  };
  
      function getRandomColor() {
          var letters = '0123456789ABCDEF';
          var color = '#';
          for (var i = 0; i &lt; 6; i++ ) {
              color += letters[Math.floor(Math.random() * 16)];
          }
          return color;
      }
  
  var map = new ol.Map({
    layers: [
    new ol.layer.Vector({
    source: vectorSource,
    style: new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: 'rgba(0, 0, 255, 0.0)',
        width: 0.3
      }),
       fill : new ol.style.Fill({
     color: getRandomColor()
    })
    })
  })
    ],
    target: document.getElementById('mapid'),
    view: new ol.View({
      center: [-1095791.453557, 3422374.879112],
      maxZoom: 19,
      zoom: 5
    })
  });
  </code></pre>
  
  <p>my dropdownlist code :</p>
  
  <pre><code>&lt;select class='Nom' name="pam" id="pam" onchange="update()"&gt;
  &lt;option value=""&gt;--- Select Layer ---&lt;/option&gt;
  [insert_php]
  $conn_string = "host=localhost port=5432 dbname=postgres user=postgres password=";
  $conn = pg_connect($conn_string);
  
  
   $sql = pg_query($conn, "SELECT * FROM especes");
  
  while($ligne_liste=pg_fetch_array($sql)) {
      echo '&lt;option value="'.$ligne_liste['nom'].'"&gt;'.$ligne_liste['nom']."&lt;/option&gt;\n";
  }
  echo '&lt;/select&gt;';
  [/insert_php]
  </code></pre>
  
  <p>and then i followed the answer here to call the onchage event in <code>functions.php</code>:
  <a href="https://wordpress.stackexchange.com/questions/248026/add-onchange-to-select-in-a-wp-form">https://wordpress.stackexchange.com/questions/248026/add-onchange-to-select-in-a-wp-form</a></p>
  
  <pre><code>function addAttributeToDropdown($html_content){
    $html_content = str_replace('&lt;select','&lt;select onchange="update()"',$html_content);
    return $html_content; 
  }
  
  add_filter('wp_dropdown_cats','addAttributeToDropdown');
  </code></pre>