Foros del Web » Programando para Internet » Javascript »

Agregar filas para insertar datos en un formulario

Estas en el tema de Agregar filas para insertar datos en un formulario en el foro de Javascript en Foros del Web. Hola espero alguien pueda ayudarme a resolver un problema que tengo con algunas funciones de javascript(Del cual soy un novato). La idea es agregar 'n' ...
  #1 (permalink)  
Antiguo 10/05/2006, 14:09
 
Fecha de Ingreso: mayo-2006
Mensajes: 10
Antigüedad: 18 años
Puntos: 0
Agregar filas para insertar datos en un formulario

Hola espero alguien pueda ayudarme a resolver un problema
que tengo con algunas funciones de javascript(Del cual soy un novato).
La idea es agregar 'n' filas(la fila consta de 4 campos) en las cuales necesitamos introducir información, de los cuales 2 de los campos que contiene la fila no se insertan manualmente, sino que mediante la apertura de una ventana(productos y cliente) seleccionamos el que sera ingresado en dicho campo; la fila tiene mas o menos el siguiente formato

En la primera fila coloca los datos sin mayor problema puesto que esta es mandada a la pantalla desde el script que esta en php, el problema es cuando agregamos una fila nueva; al momento de intentar ingresar los datos en los campos uno y dos, los botones funcionan y muestran las ventanas, pero no insertan los datos en el campo de texto, supongo que el problema esta en la funcion que agrega la fila puesto que no existe alguna variable que tome el valor del dato a ingresar, y desafortunadamente como mencione anteriormente no tengo conocimiento en javascript(aunke ya comence a estudiar) El codigo de lo anterior es el siguiente:

<table border="0" id="base" width="100%">
<tr class="celda">

<td width="20%" style="padding:3px;"></font>Cuenta</td>
<td width="20%" style="padding:3px;"></font>Producto</td>
<td width="15%" style="padding:3px;">Fecha de compra</td>
<td width="15%" style="padding:3px;">Cantidad</td>
<td width="30%" style="padding:3px;">&nbsp;</td>
<td>
<input type="button" class="boton" value="[+]" onClick="addNewRow(event)" alt="Adicionar">&nbsp;
<input type="button" class="boton" value="[-]" onClick="removeLastRow(event)" alt="Remover">
</td>
</tr>
<tr id="example" class="celda">

<td>
<input id='account_name1' size="10" name='account_name1' type='text' readonly> <img src='{IMAGE_PATH}search.gif' onclick='return window.open("index.php?xxxxxxxxxxxxx","test","widt h=600,height=400,resizable=1,scrollbars=1") align='absmiddle' style='cursor:hand;cursor:pointer'></td>

<td style='padding:3px;'><input id='product_name1' size="10"name='product_name1' type='text' readonly> <img src='{IMAGE_PATH}search.gif' onclick='return window.open("index.phpxxxxxxxxxxxxxxxxxxxxxx","tes t","width=600,height=400,resizable=1,scrollbars=1" ) align='absmiddle' style='cursor:hand;cursor:pointer'></td>

<td>
<select class="combo" name="operator[]" id="opera">
<option value="January">Enero</option>
<option value="January">Febrero</option>
<option value="in">Marzo</option>
<option value="notin">Abril</option>
<option value="notin">Mayo</option>
<option value="Diciembr">Junio</option>
<option value="in">Julio</option>
<option value="notin">agosto</option>
<option value="Diciembr">Septiembre</option>
<option value="in">Octubre</option>
<option value="notin">Noviembre</option>
<option value="">Diciembre</option>

</select>
</td>
<td>
<input name="values[]" type="text" size="10" id="value">
<input type="hidden" name="btnAction" value="next">
</td>
<td>&nbsp;</td>
</tr>
</table>

<script type="text/javascript" language="JavaScript">

function addNewRow(){
var TABLE = document.getElementById("base");
var TROW = document.getElementById("example");

var content = TROW.getElementsByTagName("td");
var newRow = TABLE.insertRow(-1);
newRow.className = TROW.attributes['class'].value;
insertLOselect(content,newRow);

var newRow2 = TABLE.insertRow(-1);
newRow2.className = TROW.attributes['class'].value;
//window.alert(content);
copyRow(content,newRow2);
}
function removeLastRow() {
var TABLE = document.getElementById("base");
if(TABLE.rows.length > 2) {
TABLE.deleteRow(TABLE.rows.length-1);
TABLE.deleteRow(TABLE.rows.length-1);
}
}

function appendCell(Trow, txt) {
var newCell = Trow.insertCell(Trow.cells.length)
newCell.innerHTML = txt
}

function copyRow(content,Trow) {
var cnt = 0;
for (; cnt < content.length; cnt++) {
appendCell(Trow, content[cnt].innerHTML);
}
}

function insertLOselect(content,Trow) {
var cnt = 0;
for (; cnt < content.length-1; cnt++) {
appendCell(Trow, '&nbsp;');
}
}
</script>

Espero puedan darne una orientación sobre como resolver el problema.

Saludos,
  #2 (permalink)  
Antiguo 13/02/2008, 11:46
 
Fecha de Ingreso: febrero-2008
Mensajes: 2
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Agregar filas para insertar datos en un formulario

Estoy mas o menos en las mismas, creo que soy menos experto que vos, pero te comparto mi código como lo llevo hasta el momento... depronto te sirve, aunque lo que quisiera es hacer una sumatoria de las columnas de las tablas...
Yo utilizo formularios con melodysoft... y el problema es que no sé como me puede enviar los datos de las tablas, aquí va mi código, espero que te sirva

<HTML>
<HEAD>
<TITLE>Prueba de formulario "Eselente"</TITLE>




<script language="JavaScript">
function A(form)
{

if (form.nombre.nombre == 0)
alert("Bien, "+form.neto.value+" ! La entrada es ok!")
var tx="<table border=1 cellpadding=”5” cellspacing=”0” width=”60%” summary=”Cotización en línea”><tr><td>"+form.equipos.options[form.equipos.selectedIndex].text+"<td>"+" $ "+" "+form.equipos.options[form.equipos.selectedIndex].value+"<td>"+document.formu.cantidad.value+""+" kg"+"<td>"+document.formu.neto.value+"</td></tr></table>";
document.body.innerHTML+=tx;


}
</script>


<SCRIPT LANGUAGE="JavaScript">

function ver(form) {
var num1, num2
var suma
document.formu.campo.value="$ "+(form.equipos.options[form.equipos.selectedIndex].value)

num1=(form.equipos.options[form.equipos.selectedIndex].value)

num2=document.formu.cantidad.value

suma=num1*num2

document.formu.neto.value = (suma)

} </SCRIPT>


<SCRIPT LANGUAGE="JavaScript">
function multi(form) {
var num1, num2

var suma

num1=(form.equipos.options[form.equipos.selectedIndex].value)

num2=document.formu.cantidad.value

suma=num1*num2

document.formu.neto.value = suma

} </SCRIPT>

</HEAD>
<BODY>
<FORM NAME="formu" form method="post" action="http://forms.melodysoft.com">
<input type="hidden" name="id" value="CÓDIGO_IDENTIFICATIVO_DEL_FORMULARIO">


Su nombre:<BR>
<input type="text" name="nombre" tabindex = "1">
<BR>
E-Mail:<BR> <input type="text" name="email" tabindex = "2">
<BR>
Empresa:<BR> <input type="text" name="email" tabindex = "3">
<BR>
Mensaje:<BR> <textarea name="mensaje" tabindex = "4"></textarea>
<BR>
Producto: <BR>
<SELECT NAME="equipos" onChange="ver(this.form)" tabindex = "5">
<option value="0">Escoja...</option>
<option value="1000">Pulmón</option>
<option value="2000">Corazón</option>
<option value="3500">Lengua</option>
<option value="2454">Hígado</option>
<option value="5879">Cayos</option>
<option value="6525">Criadillas</option>

</SELECT>
<BR>Precio Unitario:<BR> <input type="text" Name="campo" style="border:0;"><BR>
Cantidad (Kilos) :<BR> <INPUT TYPE="text" NAME = "cantidad" onKeyUp="multi(this.form)" tabindex = "6">Kg.<BR>
Subtotal: <BR><input type="text" Name="neto" value = 0 style="border:0;"><BR><BR>

<BR><BR><input type="submit" value="Enviar" tabindex = "8">
<input type="reset" value="Borrar" tabindex = "9"><BR><BR>
<input type="button" name="c" value="Agregar" onClick="A(this.form);"><BR><BR>
Cotización:<BR> <textarea name="mensaje1" tabindex = "10"></textarea><BR>
TOTAL COTIZACIÓN: <BR><input type="text" Name="total" value=0><BR><BR>




<BR>
</FORM>
</BODY>
</HTML>
  #3 (permalink)  
Antiguo 13/02/2008, 16:56
 
Fecha de Ingreso: febrero-2008
Mensajes: 2
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Agregar filas para insertar datos en un formulario

Esta es otra forma, aún falta pulirlo y terminarlo...

<HTML>
<HEAD>
<TITLE>Prueba de formulario "Eselente"</TITLE>

<script type="text/javascript">

function opera(form) {
var numero1
var numero2
var suma

numero1 = parseFloat(document.formu.total.value)
numero2 = parseFloat(document.formu.neto.value)
suma = numero1+numero2
document.formu.total.value = suma


}


function resuelve(form) {


document.formu.eq.value = ""
document.formu.neto.value = ""
document.formu.campo.value = ""
document.formu.cantidad.value = ""

}
</script>


<script type="text/javascript">

function $(x) { return document.getElementById(x); }

function addOpt(oCntrl, sTxt){
if(document.formu.campo.value==""){
alert('Debe escoger un producto');
exit;
}
else
if(document.formu.cantidad.value==""){

alert('Debe digitar una cantidad');
exit;
}
else
var sVal = sTxt;
var selOpcion = new Option(sTxt, sVal);
var iPos = oCntrl.options.length;
oCntrl.options[iPos] = selOpcion;

}
</script>





<SCRIPT LANGUAGE="JavaScript">

function ver(form) {
var num1, num2
var suma
document.formu.campo.value="$ "+(form.equipos.options[form.equipos.selectedIndex].value)
document.formu.eq.value = (form.equipos.options[form.equipos.selectedIndex].text)

num1=(form.equipos.options[form.equipos.selectedIndex].value)

num2=document.formu.cantidad.value

suma=num1*num2




document.formu.neto.value = (suma)

} </SCRIPT>


<SCRIPT LANGUAGE="JavaScript">
function multi(form) {
var num1, num2

var suma

num1=(form.equipos.options[form.equipos.selectedIndex].value)

num2=document.formu.cantidad.value

suma=num1*num2

document.formu.neto.value = suma

} </SCRIPT>


<BODY>
<FORM NAME="formu" form method="post" action="http://forms.melodysoft.com">
<input type="hidden" name="id" value="pablito153">


Su nombre:<BR>
<input type="text" name="nombre" id = "nombre1" tabindex = "1">
<BR>
E-Mail:<BR> <input type="text" name="email" tabindex = "2">
<BR>
Empresa:<BR> <input type="text" name="empresa" tabindex = "3">
<BR>
Mensaje:<BR> <textarea name="mensaje" tabindex = "4"></textarea>
<BR>
Producto: <BR>
<SELECT NAME="equipos" id= "equipos1" onChange="ver(this.form)" tabindex = "5">
<option value="0">Escoja...</option>
<option value="1000">Pulmón</option>
<option value="2000">Corazón</option>
<option value="3500">Lengua</option>
<option value="2454">Hígado</option>
<option value="5879">Cayos</option>
<option value="6525">Criadillas</option>

</SELECT>
<BR>Precio Unitario:<BR> <input type="text" Name="campo" style="border:0;"><BR>
Cantidad (Kilos) :<BR> <INPUT TYPE="text" id = "cant" NAME = "cantidad" onKeyUp="multi(this.form)" tabindex = "6">Kg.<BR>
Subtotal: <BR><input type="text" id= "subs" Name="neto" value = 0 style="border:0;"><BR>




<input type="text" id="espacios" value= "____" style="border:0;"><BR>
<input type="text" name= "eq" id="equipos2" value= "" style="border:0;"><BR><br/>



<select id="elSelect" size="10" onchange = "seleccionar(this.form)" >
<option value="prod">PRODUCTO</option>
</select>

<select id="elSelect1" size="10" >
<option value="val">VL. UN</option>
</select>

<select id="elSelect2" size="10" >
<option value="CANT">CANTIDAD</option>
</select>

<select id="elSelect3" size="10" >
<option value="neto">NETO</option>
</select>

<BR>TOTAL COTIZACIÓN: <BR><input type="text" Name="total" value=0>
<input type="submit" value="Enviar" tabindex = "8">
<input type="reset" value="Borrar" tabindex = "9">


</FORM>
<button onclick="opera(this.form);addOpt( $('elSelect'), $('equipos2').value);addOpt( $('elSelect1'),$('equipos1').value);addOpt( $('elSelect2'),$('cant').value);addOpt( $('elSelect3'),$('subs').value);resuelve(this.form )">Agrega ítem a la cotización >> </button>
</BODY>
</HTML>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:06.