Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/03/2013, 10:42
hextrem
 
Fecha de Ingreso: febrero-2013
Mensajes: 21
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: id autogenearado

te envio todo el codigo para que lo veas
Código Javascript:
Ver original
  1. function seleccion(){
  2.                 if(window.XMLHttpRequest){
  3.                     obj=new XMLHttpRequest();
  4.                 }
  5.                 else if(window.AxtiveXObject){
  6.                     obj=new AxtiveXObject("Microsoft.XMLHttp");
  7.                 }
  8.                 else{alert("No dispone de ajax");
  9.                         return;
  10.             }
  11.                
  12.                 var seci = document.getElementById("secion");
  13.                 var secion = seci.options[seci.selectedIndex].value;
  14.                
  15.                 obj.open("GET","lista?secion="+secion,true);
  16.                 obj.onreadystatechange=retorno;
  17.                 obj.send(null);
  18.                
  19.             }
  20.             function retorno(){
  21.              
  22.                     if(obj.readyState==4){
  23.                     if(obj.status==200){
  24.                                      
  25.                     var raiz= obj.responseText;
  26.                     var p = eval("("+raiz+")")
  27.                                          
  28.                     var tabla = "<table border = '1'>";
  29.                     tabla +="<tr>";
  30.                     tabla +="<th>Comprar</th>";
  31.                     tabla +="<th>Producto</th>";
  32.                     tabla +="<th>Precio</th>";
  33.                     tabla += "<th>Descripcion</th>";
  34.                     tabla +="</tr>";
  35.                     for(var i = 0;i<p.length;i++){
  36.                         var ob = p[i];
  37.                     tabla += "<tr>";
  38.                     tabla += "<td>";
  39.                     tabla += "<input type='button' name='Comprar' value='Comprar' onclick='comprar()' >";
  40.                     tabla += "</td>";
  41.                     tabla += "<td id=com>";
  42.                     tabla += ob.producto+"</td>";
  43.                     tabla += "<td>"+ob.precio+"</td>";
  44.                     tabla += "<td>"+ob.descripcion+"</td>";
  45.                     tabla += "</tr>";
  46.                    
  47.                 }
  48.                
  49.                     tabla += "</table>"
  50.                     document.getElementById("dato").innerHTML=tabla;
  51.                    
  52.                                  }
  53.                                  
  54.                     }}
  55.            function comprar(){
  56.          
  57.                 var pro = document.getElementById("com").innerHTML;
  58.                
  59.                 if(window.XMLHttpRequest){
  60.                     or=new XMLHttpRequest();
  61.                 }
  62.                 else if(window.AxtiveXObject){
  63.                     or=new AxtiveXObject("Microsoft.XMLHttp");
  64.                 }
  65.                 else{alert("No dispone de ajax");
  66.                         return;
  67.             }
  68.            
  69.                or.open("GET","carro?pro="+pro,true);
  70.                or.onreadystatechange=lis;
  71.                or.send(null);
  72.                
  73.            }
  74.            
  75.            function lis(){
  76.              
  77.                     if(or.readyState==4){
  78.                     if(or.status==200){
  79.                                      
  80.                     var list= or.responseText;
  81.                     var l = eval("("+list+")")
  82.                                          
  83.                     var tabla = "<table border = '6'>";
  84.                     tabla +="<tr>";
  85.                     tabla +="<th>Eliminar</th>";
  86.                     tabla +="<th>Producto</th>";
  87.                     tabla +="<th>Precio</th>";
  88.                     tabla += "<th>Descripcion</th>";
  89.                     tabla +="</tr>";
  90.                     for(var i = 0;i<l.length;i++){
  91.                         var li = l[i];
  92.                     tabla += "<tr>";
  93.                     tabla += "<td>";
  94.                     tabla += "<input type='button' name='Eliminar' value='Eliminar' onclick='eliminar()' >";
  95.                     tabla += "</td>";
  96.                     tabla += "<td id=el>";
  97.                     tabla += li.producto+"</td>";
  98.                     tabla += "<td>"+li.precio+"</td>";
  99.                     tabla += "<td>"+li.descripcion+"</td>";
  100.                     tabla += "</tr>";
  101.                    
  102.                 }
  103.                
  104.                     tabla += "</table>"
  105.                     document.getElementById("te").innerHTML=tabla;
  106.                  
  107.                 }
  108.                     }}
  109.            function eliminar(){
  110.                var eli = document.getElementById("el").innerHTML;
  111.                    if(window.XMLHttpRequest){
  112.                     or=new XMLHttpRequest();
  113.                 }
  114.                 else if(window.AxtiveXObject){
  115.                     or=new AxtiveXObject("Microsoft.XMLHttp");
  116.                 }
  117.                 else{alert("No dispone de ajax");
  118.                         return;
  119.             }
  120.            
  121.                or.open("GET","elimina?eli="+eli,true);
  122.                or.onreadystatechange=lis;
  123.                or.send(null);
  124.                
  125.                
  126.              }