Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/01/2014, 13:29
sebasanmarti
 
Fecha de Ingreso: mayo-2013
Mensajes: 21
Antigüedad: 11 años
Puntos: 0
Respuesta: guardar datos pedido de formulario a mysql y consultarlos

y el js:

Código PHP:
id 0;

function 
validar_form_on_submit(form){
    if (
form.mail.value == form.mail2.value)
    {
        
alert ('Los mails son iguales');
        return 
true;
    }
    else
    {
        
alert ('Los mails ingresados deben ser iguales');
        return 
false;
    }
}


 function 
cargar_variables(){
 
    
producto_lista = new Array();
    
producto_medida1 = new Array();
 
    
divProductos document.getElementById("Productos");
    
divElegirProducto document.getElementById("elegir_producto");    
    
divElegirColor document.getElementById("codigo_elegir");    
    
divProductosComprados document.getElementById("productos_comprados");
 }

function 
agregar_producto()
{
    
document.getElementById("producto_select").selectedIndex=0;
}


function 
elegir_producto_aceptar(){

    var 
producto document.getElementById("producto_select").value;
    
// SETEA LAS VARIABLES producto_datos
    
producto_datos(producto)

    
// ARMA EL SELECT
    
var select armar_select(producto_lista"subproducto_select");
    
divElegirColor.appendChild(select);

}

function 
eliminarOpcion(){
    var 
opcion this.parentNode;
    
opcion.parentNode.removeChild(opcion);
}

function 
obtenerIndice(){
    
indice document.getElementById("subproducto_select").selectedIndex;
    
valor document.getElementById("subproducto_select").options[indice].firstChild.nodeValue;
    return(
valor);
}

function 
obtenerCantidad(){
    
valor document.getElementById("producto_cantidad").value;
    return(
valor);
}

function 
validar_subproducto(){
   if ((
obtenerIndice()) == "Elegir") {
        
alert("Debe Elegir una variedad de producto");
        return 
false;
   }
   if ((
obtenerCantidad()) == "") {
        
alert("Debe Colocar una cantidad");
        return 
false;
   }
   return 
true;
}

function 
agregar_producto_aceptar(){
    if (
validar_subproducto()) 
    {
        var 
producto_elegido obtenerIndice();
        var 
producto_cantidad obtenerCantidad();
        
agregar_lista_producto(producto_elegidoproducto_cantidad);
        
document.getElementById("producto_select").selectedIndex 0;
        
document.getElementById("subproducto_select").selectedIndex 0;
    }
}

function 
agregar_lista_producto(nombrecantidad){
    
    var 
nombre_id "lista_prod";
    
    var 
linea document.createElement("div");
    
    var 
input document.createElement("input");
    
input.setAttribute("type""text");
    
input.setAttribute("id"nombre_id id);
    
input.setAttribute("name"nombre_id id);
    
input.setAttribute("size""75");
    
input.setAttribute("value"nombre "     |     " "Cantidad:   " cantidad);
    
    var 
boton document.createElement("input");
    
boton.type "button";
    
boton.value "Quitar";
    
boton.onclick eliminarOpcion
    
    
linea.appendChild(boton);
    
linea.appendChild(input);
    
divProductosComprados.appendChild(linea);
    
id ++;
    
    
document.getElementById("producto_cantidad").value "";
}

function 
cerrar(){
    
// document.getElementById("codigo_elegir").style.display = "none";
    // document.getElementById("elegir_producto").style.display = "none";
}



 function 
armar_select(opcionesselect_id)
{
    
    
/* VACIA EL SELECT */
    
var select document.getElementById(select_id);
    while(
select.childNodes[0]){  
        
select.removeChild(select.childNodes[0]);  
    }
    
    
/* SE AGREGA UN OPTION COMODIN */
        
opcion document.createElement("option");
        
opcion.appendChild(document.createTextNode("Elegir"));
        
select.appendChild(opcion);

    
    
/* SE AGREGA UN OPTION POR CADA ELEMENTO DEL ARREGLO */
    
for (i in opciones){
        
productos opciones[i];
        
optgroup document.createElement("optgroup");
        

        for (
o in productos) {
            if (
== 0){
                
optgroup.setAttribute("label"productos[o]);        
            }
            else
            {
                
opcion document.createElement("option");
                
opcion.setAttribute("value"document.createTextNode(productos[o]));
                
opcion.appendChild(document.createTextNode(productos[o]));
                
optgroup.appendChild(opcion);
            }
        }
        
select.appendChild(optgroup);
    }
    return 
select
}
 
function 
producto_datos(producto){
    switch (
producto){
    case 
"elegir" :
        var 
lista1 = new Array ();
        
producto_lista = new Array(lista1);
        break;

//// Earthborn Holistic        
case "holistic" :
var 
lista1 = new Array ("PERROS HOLISTIC""Puppy Vantage 12 KG (EH)""Puppy Vantage 6 KG (EH)""Puppy Vantage 2,5 KG (EH)""Ocean Fusion 12 KG (EH)""Ocean Fusion 6 KG (EH)""Ocean Fusion 2,5 KG (EH)","Small Breed 12 KG (EH)""Small Breed 6 KG (EH)""Small Breed 2,5 KG (EH)");
var 
lista2 = new Array ("PERROS GRAIN FREE""Primitive Natural 12 KG (EH)""Primitive Natural 6 KG (EH)""Primitive Natural 2,5 KG (EH)""Coastal Catch 12 KG (EH)""Coastal Catch 6 KG (EH)""Coastal Catch 2,5 KG (EH)");
var 
lista3 = new Array ("GATOS HOLISTIC","Feline Vantage");
var 
lista4 = new Array ("GATOS GRAIN FREE""Primitive Feline""Wild Sea Catch");
producto_lista = new Array(lista1,lista2,lista3,lista4);
break;


////// PROPAC
case "propac" :
var 
lista1 = new Array ("Perros-Puppy""Large Breed Puppy 15 KG (PP)""Large Breed Puppy 20 KG (PP)""Performance Puppy 3 KG (PP)""Performance Puppy 8 KG (PP)""Performance Puppy 15KG (PP)""Performance Puppy 20 KG (PP)""Small Breed Puppy 3KG (PP)");
var 
lista2 = new Array ("Perros-Adulto""Large Breed Adulto 20 KG (PP)""Large Breed Adulto 15 KG (PP)""Adult Chunk 3 KG (PP)""Adult Chunk 15KG (PP)""Adult Chunk 20 KG (PP)""Adulto MINI Chunk 3 KG (PP)""Adulto MINI Chunk 8 G (PP)""Adulto MINI Chunk 15 KG (PP)""Small Breed Adulto 3 KG (PP)");
var 
lista3 = new Array ("Gatos""Kitten Food  3KG (PP)""Adult Cat 3 KG (PP)""Adult Cat 7,5KG (PP)");
var 
lista4= new Array ("Especiales""Sensitive 3KG (PP)""Sensitive 15 KG (PP)""High Performance 15 KG (PP)""Adulto Senior 3KG (PP)""Adulto Senior 7,5KG (PP)""Adulto Senior 15KG (PP)""Large Breed Senior 15 KG (PP)""Low Fat 3 KG (PP)""Low Fat 7,5 KG (PP)""Low Fat 15 KG (PP)");
producto_lista = new Array(lista1,lista2,lista3,lista4);
break;
        
////// SP
    
case "sportmix" :
        var 
lista1 = new Array ("Puppy""Puppy Food Mini Morsels 20KG (SM)");
        var 
lista2 = new Array ("Adultos""High Energy 20KG (SM)""Maitenance 20 KG (SM)""Large Breed 20 KG (SM)""High Protein 20 KG (SM)""Chunk Style 18 KG (SM)");
        var 
lista3 = new Array ("Gatos""Cat Gourmet 7,5 KG (SM)");
        
producto_lista = new Array(lista1,lista2,lista3);
        break;
        
////// Otros

    
case "otros" :
        var 
lista1 = new Array ("Arena Sanitaria""PRO CAT 4 KG""PRO CAT 9 KG");
        var 
lista2 = new Array ("Treats""Nut'r'Nipz""Rewards Mini""Rewards Strip""Rewards Sticks");
        
producto_lista = new Array(lista1,lista2);
        break;
    }



como lo guardo en la tabla? ojo que pueden ser miles de productos, necesito que se guarden todos y que despues en un query se muestren. Saludos!!!!