Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2007, 13:00
Avatar de TurKa
TurKa
 
Fecha de Ingreso: enero-2003
Ubicación: Gerli, Avellaneda
Mensajes: 543
Antigüedad: 22 años, 1 mes
Puntos: 4
Re: Como escoger elementos y guardarlos en formulario

A ver si te sirve...
Un select con los productos (nombres de los productos, no?)
Un campo de texto para cantidad
botón agregar
Textarea de solo lectura (o un campo oculto, auqnue el textarea es más conveniente) donde ir agregando las selecciones del usuario.

Algo así:

Código HTML:
<script language="javascript">
function agregarProds(form) {
	form.pedido.value += form.cant.value + ", " + form.nombreProd.options[form.nombreProd.selectedIndex].value + "\n";
}
</script>
<form name="formPedido">
<input type="text" name="cant" size=2 value=1>
<select name="nombreProd">
<option value="Galletitas Cerealitas">Galletitas Cerealitas</option>
<option value="Galletitas Criollitas">Galletitas Criollitas</option>
</select>
<input type=button value=Agregar onClick="agregarProds(this.form)">
<br>
<textarea name="pedido" rows="7" cols="43" ReadOnly></textarea>
</form> 
Incluso también podés agregar precio e ir sumando los costos:

Código HTML:
<script language="javascript">
function agregarProds(form) {
	precioUnidad = parseFloat(form.nombreProd.options[form.nombreProd.selectedIndex].value);
	cant = parseInt(form.cant.value);
	subt = precioUnidad*cant;
	form.pedido.value += form.cant.value + ", " + form.nombreProd.options[form.nombreProd.selectedIndex].text + " ($" + precioUnidad + "): $" + subt + "\n";
	suma = parseFloat(form.total.value);
	form.total.value = suma+subt;
}
</script>
<form name="formPedido">
<input type="text" name="cant" size=2 value=1>
<select name="nombreProd">
<option value="4.90">Galletitas Cerealitas</option>
<option value="3.75">Galletitas Criollitas</option>
</select>
<input type=button value=Agregar onClick="agregarProds(this.form)">
<br>
<textarea name="pedido" rows="7" cols="43" ReadOnly></textarea>
<br>
TOTAL: $ <input type="text" name="total" size=6 value=0 ReadOnly>
</form> 
Espero te sea de ayuda

Saludos!!

Post Edición
Se me ocurrió que también podés cargar los prods al pedido dentro de un select para que se puedan eliminar:

Código HTML:
<script language="javascript">
numeroOpciones = 0;
function agregarProds(form,borrar) {
	if(borrar == 0) {
		precioUnidad = parseFloat(form.nombreProd.options[form.nombreProd.selectedIndex].value);
		cant = parseInt(form.cant.value);
		subt = precioUnidad*cant;
		nuevoProd = form.cant.value + ", " + form.nombreProd.options[form.nombreProd.selectedIndex].text + " ($" + precioUnidad + "): $" + subt + "\n";
		suma = parseFloat(form.total.value);
		form.total.value = suma+subt;
		form.seleccion.options[numeroOpciones] = new Option (nuevoProd,subt);
		numeroOpciones++;
	} else {
		MontoArestar = parseFloat(form.seleccion.options[form.seleccion.selectedIndex].value);
		total = parseFloat(form.total.value);
		form.total.value = total-MontoArestar;
		form.seleccion.options[form.seleccion.selectedIndex] = null;
		numeroOpciones--;
	}
}

function hacerPedido(form) {
	if(form.seleccion.options.length > 1) {
		for(i=0;i<form.seleccion.options.length;i++) {
			form.pedido.value += form.seleccion.options[i].text + "\n"
		}
	} else {
		form.pedido.value = form.seleccion.options[0];
	}
form.submit();
}
</script>
<form name="formPedido">
<input type="text" name="cant" size=2 value=1>
<select name="nombreProd">
<option value="4.90">Galletitas Cerealitas</option>
<option value="3.75">Galletitas Criollitas</option>
</select>
<input type=button value=Agregar onClick="agregarProds(this.form,0)">
<br>
<select size="8" name="seleccion" style="width: 400px;"></select>
<br>
<input type="button" value="Eliminar producto seleccionado" name="del" onClick="agregarProds(this.form,1)"><br>
<br><textarea name="pedido" rows="1" cols="32" ReadOnly style="height: 1px; width: 400px"></textarea><br>
TOTAL: $ <input type="text" name="total" size=6 value=0 ReadOnly>
<input type="button" value="Realizar Pedido" name="enviar" onClick="hacerPedido(this.form)">
</form> 
__________________
Programación LAMP con Scrum y XP
www.eugeniabahit.com.com.ar

Última edición por TurKa; 31/05/2007 a las 13:32 Razón: se me ocurrió una idea más...