I'm creating multiple form retrieving data from jquery. after that i want to work with individual form without sending the form but, i'm having problems retrieving the value of the inputs. they are all undefined in the alert tag. paste my code. thanks for all
<script>
$("#select_idioma").bind('click',function(){
cargatraducciones($("#select_idioma").val());
});
function cargatraducciones(idi){
$('#listadopalabras').hide("fast");
$('#cargando').fadeIn(1000);
$.ajax({
type: "POST",
url: "../includes/ajax.php",
dataType : "json",
data: "opc=traducciones&idi="+idi,
success: function(datos){
crealistado(datos,idi);
}
});
}
function crealistado(datos,idi){
var html ="";
if(datos.length ==0){
html +="<div id='errors'>No hay datos disponibles para mostrar</div>";
}else{
html +="<h2>Listado de palabras a traducir</h2>";
html += "<div class='nota'>Las palabras pendientes para traducir, aparecen con el texto traducir. Escriba la traducción y pulse en guardar.</div>";
for(i=0; i < datos.length; i++){
html += "<form style='background:";
if(datos[i].valor == "traducir"){
html += "red;";
}else{
html += "#f2f2f2;";
}
html+= "border-radius:5px; margin-top:5px;margin-bottom:5px; padding:5px 10px' action ='' method=''>";
html += "<a href='eliminar.php?tipo=traduccion&id="+datos[i].id+"' onclick=\"return confirm('¿Desea elminiar la palabra "+datos[i].nombre+"?')\"><img src='../imatges/iconos/delete_24.png'/></a>";
html += "<input style='display:none' type='text' name='idt' value='"+datos[i].id+"'/>";
html += "<div style='width:700px'>"+datos[i].nombre+"</div>";
html += "<input style='width:700px' type='text' name='valor"+i+"' id='valor"+i+"' value='"+datos[i].valor+"'/>";
html += "<input style='margin-left:10px' type='button' class='button"+i+"' value='Modificar' />";
html += "</form>";
html += "<hr style='margin:0; margin-bottom:2px' />";
}
}
$('#cargando').hide("fast");
$('#listadopalabras').html(html);
$("#listadopalabras").fadeIn(1000);
var total = datos.length;
procesa(total);
}
function procesa(total){
for ( i=0; i<total; i++){
$(".button"+i).click(function() {
alert($("input#valor"+i).val());
// validate and process form here
var valor = $("input#valor"+i).val();
if (valor == "") {
alert("debe escribir un texto para la traducción");
$("input#valor"+i).focus();
return false;
}
alert("clicado");
});
}
}
</script>