Ayuda con Script

From: Date: Wed, 16 Mar 2005 18:12:52 +0000
Subject: Ayuda con Script
Groups: php.general.es 
Request: Send a blank email to general-es+get-53665@lists.php.net to get a copy of this message
Buenos días a todos y un saludo desde México. Acudo a la amable ayuda de ustedes ya que tengo un problema con un archivo PHP que me ha traído de cabezas durante varios días y no logro resolver. Ojalá ustedes me puedan echar una luz al respecto. Sucede que tengo un formulario, en el que necesito crear campos adicionales de forma dinámica con forme se vayan necesitando. tengo un JS que me ayuda a resolver esa necesidad con solo darle click a un botón para que me agregue dichos campos adicionales tantas veces lo requiera (actualmente lo tengo con un máximo de 10). El problema radica en que cuando creo esos campos adicionales, necesito distinguir, si se puede llamar de alguna manera "lotes" de cada 4 campos (los principales: nombre, email, teléfono, dirección). he tratado de agregarle una simple línea divisoria entre ellos en HTML (<HR>) pero no he podido conseguirlo. He leído cuanto manual he encontrado en google, pero de ningunas de las 20 mil pruebas realizadas me ha dado resultado. Sé que es un problema de JS y no de PHP pero creo que ustedes me podrían dar al menos una luz de qué puedo hacer para resolver este problema que no me deja avanzar. A continuación les envío un código de ejemplo como el que estoy haciendo: <html> <head> <SCRIPT> var totalDestinos=1; function addField (parentObj, fieldType, fieldName, fieldValue, fieldsize) { if (document.getElementById) { var input = document.createElement('INPUT'); if (document.all) { // what follows should work // with NN6 but doesn't in M14 input.type = fieldType; input.name = fieldName; input.id = fieldName; input.value = fieldValue; input.size = fieldsize; } else if (document.getElementById) { // so here is the // NN6 workaround input.setAttribute('type', fieldType); input.setAttribute('name', fieldName); input.setAttribute('id', fieldName); input.setAttribute('value', fieldValue); input.setAttribute('size', fieldsize); } parentObj.appendChild(input); } } /** * Función que adiciona un campo de destino (nombre, email) a la forma. **/ function adicionarDestino(parentTable, maxDestinos, size) { totalDestinos++; if (totalDestinos > maxDestinos) { alert('No puede enviar la tarjeta a más de ' + maxDestinos + ' usuarios!'); return; } var tableRow = window.document.createElement("TR"); var tableCol1 = window.document.createElement("TD"); var tableCol2 = window.document.createElement("TD"); var tableRow2 = window.document.createElement("TR"); var tableCol21 = window.document.createElement("TD"); var tableCol22 = window.document.createElement("TD"); var fieldType = 'text'; var fieldDestinatarioName = 'nombreDestinatario' + totalDestinos; var fieldDestinatarioEmail = 'emailDestinatario' + totalDestinos; var fieldDestinatarioTelefono = 'telefonoDestinatario' + totalDestinos; var fieldDestinatarioDireccion = 'direccionDestinatario' + totalDestinos; document.frm_envio.totalDestinos_php.value=totalDestinos; addField (tableCol1, fieldType, fieldDestinatarioName, '', size); addField (tableCol2, fieldType, fieldDestinatarioEmail, '', size); tableRow.appendChild(tableCol1); tableRow.appendChild(tableCol2); parentTable.appendChild(tableRow); addField (tableCol21, fieldType, fieldDestinatarioTelefono, '', size); addField (tableCol22, fieldType, fieldDestinatarioDireccion, '', size); tableRow2.appendChild(tableCol21); tableRow2.appendChild(tableCol22); parentTable.appendChild(tableRow2); } function eliminarObjeto(objeto){ objeto.style.display="none"; return true; } function valores(nombre,valor){ var elemento; var nombreElemento;elemento=document.getElementById(nombre); if(elemento==null){ return; } elemento.value=valor; nombreElemento=nombre.substr(0,(nombre.length-1)); elemento=document.getElementById(nombreElemento); if(elemento!=null){ elemento.value=valor; } } </SCRIPT> </head> <body> <FORM id=frm_envio name=frm_envio onsubmit="return validarForma(document.frm_envio)" action=confirmacion.php method=post> <table cellspacing=0 cellpadding=0 width="100%" border=0> <tr> <td width="67%" height="59"> <table cellspacing=0 cellpadding=0 width="100%" border=0> <!-- TBODY No Eliminar Ya que Permite Adicionar Nuevos Campos de Email--> <tbody id=cuerpoTablaDestinos align=middle> <tr> <td width="47%" height=33 align="center" class="tablapersonalizacion">nombre</td> <td width="53%" height=33 align="center" class="tablapersonalizacion">e-mail</td> </tr> <tr> <td width="47%" align="center"> <INPUT TYPE="text" NAME="nombreDestinatario1" SIZE="40" MAXLENGTH="50"> <INPUT TYPE="hidden" NAME="totalDestinos_php"> </td> <td width="53%" align="center"> <INPUT TYPE="text" NAME="emailDestinatario1" SIZE="40" MAXLENGTH="50"> </td> </tr> <tr> <td width="47%" align="center"> telefono<p> <INPUT TYPE="text" NAME="telefonoDestinatario1" SIZE="40" MAXLENGTH="50"></td> <td width="53%" align="center"> dirección<p> <INPUT TYPE="text" NAME="direccionDestinatario1" SIZE="40" MAXLENGTH="50"></td> </tr> <tr> <td width="47%" align="center"> &nbsp;</td> <td width="53%" align="center"> &nbsp;</td> </tr> <tr> <td width="47%" align="center"> &nbsp;</td> <td width="53%" align="center"> &nbsp;</td> </tr> </tbody> </table> </td> <td width="33%" align="center" valign=top> <br> <input name=Adicionar type=button class="button" id=Adicionar onClick="adicionarLinea(); adicionarDestino(document.getElementById('cuerpoTablaDestinos'), 10,40);" value="&gt; Agregar otro destinatario &lt;"> </td> </tr> </table> <br><br><input name="accion" type="submit" class="button" value="Enviar >"> </form> </body> </html> Le agradeceré muchisimo si alguien me puede ayudar a resolver este inconveniente que ya me trae loco por varios días. Disculpen el OFF TOPIC, pero de verdad ya no tengo a quien más acudir por ayuda. Muchisimas gracias de antemano por toda su colaboración al respecto. Henry Torrealba

« previous php.general.es (#53665) next »