title: Using JavaScript function for a parameter of a PHP function
body: <p>I would like to use the result of a JavaScript function for the parameter of a PHP function.</p>
  
  <p>This will generate a random ID:</p>
  
  <pre><code>  function generate_id()
      {
          var text = "";
          var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  
          for( var i=0; i &lt; 5; i++ )
              text += possible.charAt(Math.floor(Math.random() * possible.length));
  
          return text;
      }
  </code></pre>
  
  <p>The 5th parameter of the function bellow should contain the result of the JS function. </p>
  
  <pre><code>$anrede_frau = $html_helper-&gt;form_input("radio", "friend_anrede[]", array("anrede" =&gt; array("Frau", "Madame", "Signora")), "input_field_left", 'anrede_&lt;script&gt;generate_id()&lt;/script&gt;', 'left');
  $anrede_herr = $html_helper-&gt;form_input("radio", "friend_anrede[]", array("anrede" =&gt; array("Herr", "Monsieur", "Signor")), "input_field_left", 'anrede_&lt;script&gt;generate_id()&lt;/script&gt;');
  </code></pre>
  
  <p>I tried to use something like <code>anrede_&lt;script&gt;generate_id()&lt;/script&gt;</code> but that doesn't work. How can I get this fixed?</p>
  
  <p><strong>EDIT:</strong> 
  The idea is to generate a new input field with a random ID. this should happen whenever a button with the ID #addMore is clicked. This is the way I am doing it:</p>
  
  <pre><code>&lt;script&gt;
  $(function() {
    $("#addMore").click(function(e) {
           e.preventDefault();
           $(".form_area").append('&lt;br&gt;&lt;br&gt;&lt;?= $html_helper-&gt;form_input("radio", "friend_anrede[]", array("anrede" =&gt; array("Frau", "Madame", "Signora")), "input_field_left", 'anrede_frau_ + generate_id() + '); ?&gt;');
           $(".form_area").append('&lt;?= $html_helper-&gt;form_input("radio", "friend_anrede[]", array("anrede" =&gt; array("Herr", "Monsieur", "Signor")), "input_field_left", 'anrede_herr_ + generate_id() + '); ?&gt;');
           $(".form_area").append('&lt;?= $html_helper-&gt;form_input("text", "friend_vorname[]", array("vorname" =&gt; array("Vorname", "Prénom", "Nome")), "input_field_left"); ?&gt;');
           $(".form_area").append('&lt;?= $html_helper-&gt;form_input("text", "friend_name[]", array("name" =&gt; array("Name", "Nom", "Cognome")), "input_field_right"); ?&gt;');
           $(".form_area").append('&lt;?= $html_helper-&gt;form_input("text", "friend_strasse_nr[]", array("strasse" =&gt; array("Strasse / Nr.", "Rue/n°", "Indirizzo"))); ?&gt;');
           $(".form_area").append('&lt;?= $html_helper-&gt;form_input("text", "friend_plz_ort[]", array("ort" =&gt; array("PLZ / Ort", "NPA / localité", "NPA / Località"))); ?&gt;');
           $(".form_area").append('&lt;p class="de"&gt;Bitte vollständig ausfüllen.&lt;/p&gt;&lt;p class="fr"&gt;Veuillez remplir complètement.&lt;/p&gt;&lt;p class="it"&gt;Si prega di compilare integralmente.&lt;/p&gt;');
        });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Either with PHP or with JavaScript I need to be able to add an ID to my input fields with the type of radio. I hope that makes my question a bit clearer.</p>