Foros del Web » Programando para Internet » Javascript »

Combinar Javascript con php

Estas en el tema de Combinar Javascript con php en el foro de Javascript en Foros del Web. Hola, tengo un codigo javascript que hace que llene uno combos relacionados en un php. El problema es que cuando quiero enviar la información que ...
  #1 (permalink)  
Antiguo 24/05/2011, 14:25
 
Fecha de Ingreso: enero-2010
Mensajes: 150
Antigüedad: 14 años, 3 meses
Puntos: 0
Combinar Javascript con php

Hola, tengo un codigo javascript que hace que llene uno combos relacionados en un php. El problema es que cuando quiero enviar la información que contienen los combos a una base de datos mysql, no me guarda los datos. Que tendria que modificar de este codigo para poder enviar la informacion que contiene los combos. Estos funcionan correctamente y muestran la informacion necesaria, pero me falta eso para que funcione completo.

Espero que puedan ayudarme, Aqui el codigo:

Código Javascript:
Ver original
  1. var _disable_empty_list=false;
  2.     var _hide_empty_list=false;
  3.      
  4.     // ------
  5.      
  6.     ///// DynamicDrive.com added function/////////////
  7.      
  8.     var onclickaction="alert"
  9.      
  10.     function goListGroup(){
  11.     for (i=arguments.length-1;i>=0; i--){
  12.     if (arguments[i].selectedIndex!=-1){
  13.     var selectedOptionvalue=arguments[i].options[arguments[i].selectedIndex].value
  14.     if (selectedOptionvalue!=""){
  15.     if (onclickaction=="alert")
  16.     alert(selectedOptionvalue)
  17.     else if (newwindow==1)
  18.     window.open(selectedOptionvalue)
  19.     else
  20.     window.location=selectedOptionvalue
  21.     break
  22.     }
  23.     }
  24.     }
  25.     }
  26.      
  27.     ///// END DynamicDrive.com added function//////
  28.      
  29.      
  30.     if (typeof(disable_empty_list)=="undefined") { disable_empty_list=_disable_empty_list; }
  31.     if (typeof(hide_empty_list)=="undefined") { hide_empty_list=_hide_empty_list; }
  32.      
  33.     var cs_goodContent=true, cs_M="M", cs_L="L", cs_curTop=null, cs_curSub=null;
  34.      
  35.     function cs_findOBJ(obj,n) {
  36.       for (var i=0; i<obj.length; i++) {
  37.         if (obj[i].name==n) { return obj[i]; }
  38.       }
  39.       return null;
  40.     }
  41.     function cs_findContent(n) { return cs_findOBJ(cs_content,n); }
  42.      
  43.     function cs_findM(m,n) {
  44.       if (m.name==n) { return m; }
  45.      
  46.       var sm=null;
  47.       for (var i=0; i<m.items.length; i++) {
  48.         if (m.items[i].type==cs_M) {
  49.           sm=cs_findM(m.items[i],n);
  50.           if (sm!=null) { break; }
  51.         }
  52.       }
  53.       return sm;
  54.     }
  55.     function cs_findMenu(n) { return (cs_curSub!=null && cs_curSub.name==n)?cs_curSub:cs_findM(cs_curTop,n); }
  56.      
  57.     function cs_contentOBJ(n,obj){ this.name=n; this.menu=obj; this.lists=new Array(); this.cookie=""; }; cs_content=new Array();
  58.     function cs_topmenuOBJ(tm) { this.name=tm; this.items=new Array(); this.df=0; this.addM=cs_addM; this.addL=cs_addL; }
  59.     function cs_submenuOBJ(dis,link,sub) {
  60.       this.name=sub;
  61.       this.type=cs_M; this.dis=dis; this.link=link; this.df=0;
  62.      
  63.       var x=cs_findMenu(sub);
  64.       this.items=x==null?new Array():x.items;
  65.      
  66.       this.addM=cs_addM; this.addL=cs_addL;
  67.     }
  68.     function cs_linkOBJ(dis,link) { this.type=cs_L; this.dis=dis; this.link=link; }
  69.      
  70.     function cs_addM(dis,link,sub) { this.items[this.items.length]=new cs_submenuOBJ(dis,link,sub); }
  71.     function cs_addL(dis,link) { this.items[this.items.length]=new cs_linkOBJ(dis,link); }
  72.      
  73.     function cs_showMsg(msg) { window.status=msg; }
  74.     function cs_badContent(n) { cs_goodContent=false; cs_showMsg("["+n+"] Not Found."); }
  75.      
  76.     function cs_optionOBJ(text,value) { this.text=text; this.value=value; }
  77.     function cs_emptyList(list) { for (var i=list.options.length-1; i>=0; i--) { list.options[i]=null; } }
  78.     function cs_refreshList(list,opt,df) {
  79.       cs_emptyList(list);
  80.      
  81.       for (var i=0; i<opt.length; i++) {
  82.         list.options[i]=new Option(opt[i].text, opt[i].value);
  83.       }
  84.      
  85.       if (opt.length>0) {
  86.         list.selectedIndex=df;
  87.       }
  88.     }
  89.     function cs_getOptions(menu) {
  90.       var opt=new Array();
  91.       for (var i=0; i<menu.items.length; i++) {
  92.         opt[i]=new cs_optionOBJ(menu.items[i].dis, menu.items[i].link);
  93.       }
  94.       return opt;
  95.     }
  96.     function cs_updateListGroup(content,idx,sidx,mode) {
  97.       var i=0, curItem=null, menu=content.menu;
  98.      
  99.       while (i<idx) {
  100.         menu=menu.items[content.lists[i++].selectedIndex];
  101.       }
  102.      
  103.       if (menu.items[sidx].type==cs_M && idx<content.lists.length-1) {
  104.         var df=cs_getIdx(mode,content.cookie,idx+1,menu.items[sidx].df);
  105.      
  106.         cs_refreshList(content.lists[idx+1], cs_getOptions(menu.items[sidx]), df);
  107.         if (content.cookie) {
  108.           cs_setCookie(content.cookie+"_"+(idx+1),df);
  109.         }
  110.      
  111.         if (idx+1<content.lists.length) {
  112.           if (disable_empty_list) {
  113.             content.lists[idx+1].disabled=false;
  114.           }
  115.           if (hide_empty_list) {
  116.             content.lists[idx+1].style.display="";
  117.           }
  118.      
  119.           cs_updateListGroup(content,idx+1,df,mode);
  120.         }
  121.       }
  122.       else {
  123.         for (var s=idx+1; s<content.lists.length; s++) {
  124.           cs_emptyList(content.lists[s]);
  125.      
  126.           if (disable_empty_list) {
  127.             content.lists[s].disabled=true;
  128.           }
  129.           if (hide_empty_list) {
  130.             content.lists[s].style.display="none";
  131.           }
  132.      
  133.           if (content.cookie) {
  134.             cs_setCookie(content.cookie+"_"+s,"");
  135.           }
  136.         }
  137.       }
  138.     }
  139.     function cs_initListGroup(content,mode) {
  140.       var df=cs_getIdx(mode,content.cookie,0,content.menu.df);
  141.      
  142.       cs_refreshList(content.lists[0], cs_getOptions(content.menu), df);
  143.       if (content.cookie) {
  144.         cs_setCookie(content.cookie+"_"+0,df);
  145.       }
  146.      
  147.       cs_updateListGroup(content,0,df,mode);
  148.     }
  149.      
  150.     function cs_updateList() {
  151.       var content=this.content;
  152.       for (var i=0; i<content.lists.length; i++) {
  153.         if (content.lists[i]==this) {
  154.           if (content.cookie) {
  155.             cs_setCookie(content.cookie+"_"+i,this.selectedIndex);
  156.           }
  157.      
  158.           if (i<content.lists.length-1) {
  159.             cs_updateListGroup(content,i,this.selectedIndex,"");
  160.           }
  161.         }
  162.       }
  163.     }
  164.      
  165.     function cs_getIdx(mode,name,idx,df) {
  166.       if (mode) {
  167.         var cs_idx=cs_getCookie(name+"_"+idx);
  168.         if (cs_idx!="") {
  169.           df=parseInt(cs_idx);
  170.         }
  171.       }
  172.       return df;
  173.     }
  174.      
  175.     function _setCookie(name, value) {
  176.       document.cookie=name+"="+value;
  177.     }
  178.     function cs_setCookie(name, value) {
  179.       setTimeout("_setCookie('"+name+"','"+value+"')",0);
  180.     }
  181.      
  182.     function cs_getCookie(name) {
  183.       var cookieRE=new RegExp(name+"=([^;]+)");
  184.       if (document.cookie.search(cookieRE)!=-1) {
  185.         return RegExp.$1;
  186.       }
  187.       else {
  188.         return "";
  189.       }
  190.     }
  191.      
  192.     // ----
  193.     function addListGroup(n,tm) {
  194.       if (cs_goodContent) {
  195.         cs_curTop=new cs_topmenuOBJ(tm); cs_curSub=null;
  196.      
  197.         var c=cs_findContent(n);
  198.         if (c==null) {
  199.           cs_content[cs_content.length]=new cs_contentOBJ(n,cs_curTop);
  200.         }
  201.         else {
  202.           delete(c.menu); c.menu=cs_curTop;
  203.         }
  204.       }
  205.     }
  206.      
  207.     function addList(n,dis,link,sub,df) {
  208.       if (cs_goodContent) {
  209.         cs_curSub=cs_findMenu(n);
  210.      
  211.         if (cs_curSub!=null) {
  212.           cs_curSub.addM(dis,link||"",sub);
  213.           if (typeof(df)!="undefined") { cs_curSub.df=cs_curSub.items.length-1; }
  214.         }
  215.         else {
  216.           cs_badContent(n);
  217.         }
  218.       }
  219.     }
  220.      
  221.     function addOption(n,dis,link,df) {
  222.       if (cs_goodContent) {
  223.         cs_curSub=cs_findMenu(n);
  224.      
  225.         if (cs_curSub!=null) {
  226.           cs_curSub.addL(dis,link||"");
  227.           if (typeof(df)!="undefined") { cs_curSub.df=cs_curSub.items.length-1; }
  228.         }
  229.         else {
  230.           cs_badContent(n);
  231.         }
  232.       }
  233.     }
  234.      
  235.     function initListGroup(n) {
  236.       var _content=cs_findContent(n), count=0;
  237.       if (_content!=null) {
  238.         content=new cs_contentOBJ("cs_"+n,_content.menu);
  239.         cs_content[cs_content.length]=content;
  240.      
  241.         for (var i=1; i<initListGroup.arguments.length; i++) {
  242.           if (typeof(arguments[i])=="object" && arguments[i].tagName && arguments[i].tagName=="SELECT") {
  243.             content.lists[count]=arguments[i];
  244.      
  245.             arguments[i].onchange=cs_updateList;
  246.             arguments[i].content=content; arguments[i].idx=count++;
  247.           }
  248.           else if (typeof(arguments[i])=="string" && /^[a-zA-Z_]\w*$/.test(arguments[i])) {
  249.             content.cookie=arguments[i];
  250.           }
  251.         }
  252.      
  253.         if (content.lists.length>0) {
  254.           cs_initListGroup(content,content.cookie);
  255.         }
  256.       }
  257.     }
  258.      
  259.     function resetListGroup(n) {
  260.       var content=cs_findContent("cs_"+n);
  261.       if (content!=null && content.lists.length>0) {
  262.         cs_initListGroup(content,"");
  263.       }
  264.     }
  #2 (permalink)  
Antiguo 26/05/2011, 09:35
 
Fecha de Ingreso: septiembre-2004
Ubicación: La Plata Argentina
Mensajes: 128
Antigüedad: 19 años, 7 meses
Puntos: 9
Respuesta: Combinar Javascript con php

Hola.

Es muy dificil ayudarte porque pones un codigo muy extenso para un problema sencillo.
Te sugiero, saca todo lo que puedas de tu codigo y deja solo el combo y mira si suben los datos.
Luego empieza a agregar las distintas funciones y en algun momento repetira el error.
Para encontrar un error "dificil", siempre es conveniente aislar el codigo y probarlo por partes.

Divide y triunfaras !!!

saludos
  #3 (permalink)  
Antiguo 26/05/2011, 09:42
Avatar de chipilofan  
Fecha de Ingreso: mayo-2011
Ubicación: México
Mensajes: 59
Antigüedad: 12 años, 11 meses
Puntos: 3
Respuesta: Combinar Javascript con php

Recuerda que el select (lo que seleccione el usuario) debe ser devuelto al value (esto hara que se envie correcto a tu BD) asi se procesara y sera enviado de forma correcta, saludos.
__________________
El silencio es el arma mas grande del mundo... [Ignacio Recinos]
Pensando en la Web

Etiquetas: combinar, php
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 22:56.