I would like to use the result of a JavaScript function for the parameter of a PHP function.
This will generate a random ID:
function generate_id()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
The 5th parameter of the function bellow should contain the result of the JS function.
$anrede_frau = $html_helper->form_input("radio", "friend_anrede[]", array("anrede" => array("Frau", "Madame", "Signora")), "input_field_left", 'anrede_<script>generate_id()</script>', 'left');
$anrede_herr = $html_helper->form_input("radio", "friend_anrede[]", array("anrede" => array("Herr", "Monsieur", "Signor")), "input_field_left", 'anrede_<script>generate_id()</script>');
I tried to use something like anrede_<script>generate_id()</script>
but that doesn't work. How can I get this fixed?
EDIT: 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:
<script>
$(function() {
$("#addMore").click(function(e) {
e.preventDefault();
$(".form_area").append('<br><br><?= $html_helper->form_input("radio", "friend_anrede[]", array("anrede" => array("Frau", "Madame", "Signora")), "input_field_left", 'anrede_frau_ + generate_id() + '); ?>');
$(".form_area").append('<?= $html_helper->form_input("radio", "friend_anrede[]", array("anrede" => array("Herr", "Monsieur", "Signor")), "input_field_left", 'anrede_herr_ + generate_id() + '); ?>');
$(".form_area").append('<?= $html_helper->form_input("text", "friend_vorname[]", array("vorname" => array("Vorname", "Prénom", "Nome")), "input_field_left"); ?>');
$(".form_area").append('<?= $html_helper->form_input("text", "friend_name[]", array("name" => array("Name", "Nom", "Cognome")), "input_field_right"); ?>');
$(".form_area").append('<?= $html_helper->form_input("text", "friend_strasse_nr[]", array("strasse" => array("Strasse / Nr.", "Rue/n°", "Indirizzo"))); ?>');
$(".form_area").append('<?= $html_helper->form_input("text", "friend_plz_ort[]", array("ort" => array("PLZ / Ort", "NPA / localité", "NPA / Località"))); ?>');
$(".form_area").append('<p class="de">Bitte vollständig ausfüllen.</p><p class="fr">Veuillez remplir complètement.</p><p class="it">Si prega di compilare integralmente.</p>');
});
});
</script>
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.