Note that there are some explanatory texts on larger screens.

plurals
  1. POadd input dynamically symfony2
    text
    copied!<p>Hi I am new in symfony I have a problem to use Ajax I have this class</p> <pre><code>class categorie extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $categories_choices = array( 'VEHICULES' =&gt; array( '101' =&gt; 'Voitures', '102' =&gt; 'Motos', '103' =&gt; 'Vélos ', '104' =&gt; 'Pièces auto', '105' =&gt; 'Utilitaires / Véhicules commerciaux', '106' =&gt; 'Bateaux / Nautisme', ), 'IMMOBILIER' =&gt; array( '201' =&gt; 'Vente / Achat', '202' =&gt; 'Location', '203' =&gt; 'Colocation', '204' =&gt; 'Location vacances', '205' =&gt; 'Garages / Parkings', '206' =&gt; 'Terrains', '207' =&gt; 'Bureaux / Commerces', ), ); $builder-&gt;add('Categorie', 'choice',array( 'choices' =&gt;$categories_choices, 'required' =&gt; true , 'required' =&gt; 'Le champ est obligatoire.', 'attr' =&gt; array('onchange' =&gt; 'FormCategoryAjaxRequest(this.value)') )); $builder-&gt;add('Type', 'choice', array( 'choices' =&gt; array('m' =&gt; 'Offre', 'f' =&gt; 'demande') )); } </code></pre> <p>My idea is to use javascript, this is my function:</p> <pre><code>FormCategoryAjaxRequest(ref_doc) { if (ref_doc==101 || ref_doc==102 { var DivToAdd = document.getElementById('registration'); tempInput = document.createElement('input'); tempInput.setAttribute("type","text"); tempInput.setAttribute("id","hamza"); var newlabel = document.createElement('Label'); newlabel.setAttribute("for","hamza"); newlabel.innerHTML = " text"; DivToAdd.appendChild(newlabel); DivToAdd.appendChild(tempInput); } } </code></pre> <p>I would like to add another input when the user chooses a category type it is simple with Ajax but I didn't find a solution any idea please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload