title: Twig and javascript
body: <p>i'm creating a page that shows a chart depending on the type selected in the combo box</p>
  
  <pre><code>&lt;div id="chartdiv"&gt;&lt;/div&gt;
  
  &lt;select name="graphe" id="identifiantDeMonSelect"&gt;
  &lt;option value="Column2D"&gt;Column2D
  &lt;option value="Column3D"&gt;Column3D
  &lt;option value="Pie3D"&gt;Pie3D
  &lt;option value="Pie2D"&gt;Pie2D
  &lt;/select&gt;
  &lt;input type="submit" value="Afficher" onclick="ajax()"&gt;
  
  
  &lt;script type="text/javascript"&gt;
  function ajax(){
      var xhr
  
      if (window.XMLHttpRequest) { 
          xhr = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) 
      {
          xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      if (xhr !=null)  {
      xhr.onreadystatechange = function() { type1(xhr); };
      xhr.open("GET", "{{ path('Ajax')}}", true);
      xhr.send(null);
      } else {
  
       alert("The XMLHttpRequest not supported");
  
    }}
  
  function type1(xhr){
              var docXML= xhr.responseText;
              var val_type = getSelectValue('identifiantDeMonSelect');
              var type = val_type+"";
              var str="{{ asset('Charts/Pie2D.swf') }}";
              var chart = new FusionCharts(str, "ChartId", "600", "400", "0", "0");
              chart.setXMLData(docXML);                               
              chart.render("chartdiv");
              }
  function getSelectValue(selectId)
  {
      var selectElmt = document.getElementById(selectId);
      return selectElmt.options[selectElmt.selectedIndex].value;
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Now when i simply replace <code>var str="{{ asset('Charts/Pie2D.swf') }}";</code> with <code>"{{asset('Charts/'+type+'.swf') }}"</code> in order to dynamically change the the type of the chart i obtain the following symfony error : <code>"Variable "type" does not exist in "</code>. And when i put <code>"{{ asset('Charts/"+type+".swf') }}"</code> (i just replaced ' by ") i get the page and when i click the submit button nothing happens, and inside the console (chrome's console) i get this error "<code>GET http://127.0.0.1:8888/dashboard2/Symfony/web/Charts/&amp;quot;+type+&amp;quot;.swf 404 (Not Found)</code> ". It takes it as it is <code>&amp;quot;+type+&amp;quot</code>;
  Obviously i need help, i don't know if it's a concatenation problem or it has something to do with the twig and the asset function. Thanks in advance</p>