title: get the id of selected index using set jquery and twig
body: <p>I want to get the id from a dropdownmenu list using jquery and the function set</p>
  
  <pre><code>var c = document.getElementById("dropdown1");
  var id= parseInt(c.selectedIndex) ;
  </code></pre>
  
  <p>but i want to get the id using this method</p>
  
  <pre><code>{% set id=parseInt(c.selectedIndex) %}
  </code></pre>
  
  <p>but does not work</p>
  
  <p>in fact this is my real problematic: I have a drowpdown menu list generated from and entity </p>
  
  <pre><code>-&gt;add(
              'predefinedMessage',
              'entity',
              array(
                  'empty_value' =&gt; 'Ajouter un message Prédéfini',
                  'class' =&gt; 'MyBundle:PredefinedMessage',
                  'property' =&gt; 'name',
                  'multiple' =&gt; false,
                  'error_bubbling' =&gt; true,
                  'required' =&gt; false,
                  'query_builder' =&gt; function (EntityRepository $er) use ($user) {
  
                      return $er-&gt;createQueryBuilder('u')
                          -&gt;where('u.user = :user')
                          -&gt;setParameter('user', $user);
  
                  },
  
              )
  </code></pre>
  
  <p>the message entity has many field such as: id, message, name</p>
  
  <p><a href="https://i.stack.imgur.com/B6fZ4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6fZ4.png" alt="enter image description here"></a></p>
  
  <p>so in jquery, I want to get the message value of the selected index</p>
  
  <p>my code in jquery is as follow:</p>
  
  <pre><code>var c = document.getElementById("predefinedMessage");
  
      var id= parseInt(c.selectedIndex) ;
  
      var text= "{{ form.predefinedMessage.vars.choices[id].data.message }}";
  </code></pre>
  
  <p>but always I gor an error, and the id is not defined.</p>
  
  <p>any help please for this problem</p>