Reputation: 2289
The getElementByid('projectsearch'+id)
doesn't work when I click on the link. What can be done about this? As soon as it's generated, I have no idea about how to send the form - any ideas?
var i;
for (i = 0; i < data.data.length; ++i) {
console.log(i);
var divCreator ='';
var str='projectsearch' + i;
divCreator+='<div id="grupo'+i+'">';
divCreator+='<div>';
divCreator+='<div id="tipo_'+i+'"></div>';
divCreator+='<div id="tipo_arq_abajo'+i+'"></div>';
divCreator+='</div>';
divCreator+='<div id="fotoproyectos'+i+'" ><img src="' + data.data[i].path + '" height="128" width="160"></div>';
divCreator+='<div id="nombreproyectos'+i+'" ><form method="post" name="projectsearch'+i+'" id="projectsearch'+ i +'" action="proyectos_arq.php">';
divCreator+='<span style="cursor: pointer;" onclick="document.getElementById('projectsearch'+id).submit()">"'+ data.data[i].projectName +'"</span>'
divCreator+='<input name="project_id" type="hidden" id="project_id" value="' + data.data[i].projectId + '">';
divCreator+='</form></div>';
divCreator+='</div>';
divCreator+='</div><br><br>';
//$("#contiene-pro").append(divCreator);
$("#testDiv").append(divCreator);
};
Upvotes: 0
Views: 531
Reputation: 999
You create:
var str='projectsearch' + i;
Then never use it.
Later in the code you have:
divCreator+='<span style="cursor: pointer;" onclick="document.getElementById('projectsearch'+id).submit()">"'+ data.data[i].projectName +'"</span>'
I think you mean for this to be:
divCreator+='<span style="cursor: pointer;" onclick="document.getElementById(' + str + ').submit()">"'+ data.data[i].projectName +'"</span>';
Which uses the str
variable you created as the id for the getElementById()
Upvotes: 1
Reputation: 36531
i think that should be
document.getElementById('projectsearch'+i).submit() // not id...
and escape your quotes
if you are trying to submit the form that u just created... and i cannot find "id" variable in your question...
Upvotes: 2
Reputation: 346
Please check in console for the corresponding div ids and try this syntax for getting the value
var element= $("#projectsearch"+id);
or
var element=document.getElementById("projectsearch"+id);
Upvotes: -1