Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically generated form not working properly
    primarykey
    data
    text
    <p>im having this ajax function where i populate a list of elements coming from the database dynamically. Each one of them as a display pic and a name. It has a hidden field with a variable that is being caught on the other page via POST and displays an image and some info with it.</p> <p>The problem is that sometimes the ID parameter in the hidden field doesnt seem to be sent. the form is sent but it doesnt seem to catch the hidden variable, displaying a random image and info instead of the one that im initially clicking.</p> <p>here is my code:</p> <pre><code>function absurdSearch(textoBuscar){ $.ajax({ type : "POST", url : "service.php", dataType: "json", data : { action:"absurdSearch", absurdText: textoBuscar }, success:function(data){ $("#testDiv").empty(); var i; for (i = 0; i &lt; data.data.length; ++i) { console.log(data); var divCreator =''; var str='projectsearch' + i; data.data[i].projectCategory var ProjectTypeIdName = data.data[i].projectCategory; switch (ProjectTypeIdName) { case "1": var urlFormSend='proyectos_arq.php'; var projectTypeName ='Proyectos &lt;br/&gt;Arquitectónicos'; break; case "6": var urlFormSend='proyectos_urb.php'; var projectTypeName ='Proyectos &lt;br/&gt;Urbanos'; break; case "7": var urlFormSend='arquit_pai.php'; var projectTypeName ='Arquitectura del &lt;br/&gt;Paisaje'; break; case "8": var urlFormSend='arquit_int.php'; var projectTypeName ='Arquitectura de &lt;br/&gt;Interiores'; break; case "10": var urlFormSend='arquit_trans.php'; var projectTypeName ='Arquitectura del &lt;br/&gt;Transporte'; break; } divCreator+='&lt;div id="grupo'+i+' class="typeface-js" style="font-family:GreyscaleBasic""&gt;'; divCreator+='&lt;div class="tipo-pro"&gt;'; divCreator+='&lt;div id="tipo_arq" class="tipo"&gt;'+projectTypeName+'&lt;/div&gt;'; divCreator+='&lt;div id="tipo_arq_abajo" class="abajo"&gt;&lt;/div&gt;'; divCreator+='&lt;/div&gt;'; divCreator+='&lt;div&gt;'; divCreator+='&lt;div id="tipo_'+i+'"&gt;&lt;/div&gt;'; divCreator+='&lt;div id="tipo_arq_abajo'+i+'"&gt;&lt;/div&gt;'; divCreator+='&lt;/div&gt;'; divCreator+='&lt;div id="fotoproyectos'+i+'" &gt;&lt;img src="' + data.data[i].path + '" height="128" width="160"&gt;&lt;/div&gt;'; divCreator+='&lt;div id="nombreproyectos'+i+'" &gt;&lt;form method="post" name="projectsearch'+i+'" id="projectsearch'+ i +'" action="'+urlFormSend+'"&gt;'; divCreator+='&lt;span style="cursor: pointer;" onclick="document.getElementById(\'projectsearch'+i+'\').submit()"&gt;"'+ data.data[i].projectName +'"&lt;/span&gt;' divCreator+='&lt;input name="project_id" type="hidden" id="project_id" value="' + data.data[i].projectId + '"&gt;'; divCreator+='&lt;/form&gt;&lt;/div&gt;'; divCreator+='&lt;/div&gt;'; divCreator+='&lt;/div&gt;&lt;br&gt;&lt;br&gt;'; $("#testDiv").append(divCreator); }; } }) }; </code></pre> <p>and here is the code that actually catches the POST variable. </p> <pre><code>&lt;?php require('server/php/methods.php'); $main = new main(); $project_id = $_POST['project_id']; if (empty($project_id)) { list($name, $description, $path, $_images, $next_project_id, $previous_project_id = $main-&gt;projectRandom(7); $images = json_encode($_images); } else { list($name, $description, $path, $_images, $next_project_id, $previous_project_id) = $main-&gt;projectNumber(7, $project_id); $images = json_encode($_images); } </code></pre> <p>when i check on firebug everything seems to be ok, every hidden field has the parameter (project_id) assigned. But sometimes it does work and sometimes it doesnt. </p> <p>Firebug:</p> <p><img src="https://i.stack.imgur.com/0jBwb.png" alt="Firebug"></p> <p>Any help will be appreciated</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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