Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/05/2012, 12:25
WalkmanXZ
 
Fecha de Ingreso: abril-2010
Ubicación: Mexico
Mensajes: 21
Antigüedad: 14 años
Puntos: 0
Respuesta: Mas de una funcion/evento para el atributo onclick

Sin exito aun, no se si tenga que dar el dato adicional que los eventos son bajo AJAX

el primero usa este JS
Código Javascript:
Ver original
  1. var pid=-1;
  2. var spinner=null;
  3. function thx_common(response)
  4. {
  5.     try
  6.     {
  7.         xml=response.responseXML;
  8.         remove=xml.getElementsByTagName('del').item(0).firstChild.data=="1";
  9.         lin=document.getElementById('a'+pid);
  10.         if (remove) {
  11.             table = document.getElementById('thx' + pid);
  12.             table.style.display = xml.getElementsByTagName('display').item(0).firstChild.data != 0 ?
  13.                  '' : 'none';
  14.             list = document.getElementById('thx_list' + pid);
  15.             list.innerHTML = xml.getElementsByTagName('list').item(0).firstChild.data;
  16.            
  17.             img = document.getElementById('i' + pid);
  18.             img.src = xml.getElementsByTagName('image').item(0).firstChild.data;
  19.         }
  20.         else
  21.         {
  22.             lin.innerHTML="";
  23.             lin.onclick=null;
  24.             lin.href="";
  25.             lin = null;
  26.         }
  27.     }
  28.     catch(err)
  29.     {
  30.         alert("an Error had occured please contact administrator")
  31.         alert(err);
  32.     }
  33.     finally
  34.     {
  35.         spinner.destroy();
  36.         spinner=null;
  37.         return lin;
  38.     }
  39.    
  40. }
  41. function thx_action(response)
  42. {
  43.     lin=thx_common(response)
  44.     if(lin!=null)
  45.     {
  46.         lin.onclick= new Function("","return rthx("+pid+");");
  47.         lin.href='showthread.php?action=remove_thank&pid='+pid;
  48.     }
  49. }
  50.  
  51. function rthx_action(response)
  52. {
  53.     lin=thx_common(response)
  54.     if (lin!=null)
  55.     {
  56.         lin.onclick = new Function("", "return thx(" + pid + ");");
  57.         lin.href = 'showthread.php?action=thank&pid=' + pid;
  58.     }
  59.    
  60.    
  61. }
  62.  
  63. function thx(id)
  64. {
  65.     if(spinner)
  66.         return false;
  67.     spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});
  68.     pid=id;
  69.     pb="pid="+pid;
  70.     new Ajax.Request('xmlhttp.php?action=thankyou',{method: 'post',postBody:pb, onComplete:thx_action});
  71.     return false;
  72. }
  73.  
  74. function rthx(id)
  75. {
  76.     if(spinner)
  77.         return false;
  78.     spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});
  79.     pid=id;
  80.     b="pid="+pid;
  81.     new Ajax.Request('xmlhttp.php?action=remove_thankyou',{method: 'post',postBody:b,onComplete:rthx_action});
  82.     return false;
  83. }

el segundo
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.         <!--
  3.        
  4.         var spinner=null;
  5.        
  6.         function hideuntilthanks_reload()
  7.         {
  8.             b1 = b;
  9.             if(spinner){return false;}
  10.             this.spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});
  11.             new Ajax.Request('{$mybb->settings['bburl']}/xmlhttp.php?action=hideuntilthanks_reload&my_post_key='+my_post_key, {method: 'post',postBody:"", onComplete:hideuntilthanks_done});
  12.             return false;
  13.         }
  14.        
  15.         function hideuntilthanks_done(request)
  16.         {
  17.             if(this.spinner)
  18.             {
  19.                 this.spinner.destroy();
  20.                 this.spinner = '';
  21.             }
  22.             if(request.responseText.match(/<error>(.*)<\/error>/))
  23.             {
  24.                 message = request.responseText.match(/<error>(.*)<\/error>/);
  25.                 alert(message[1]);
  26.             }
  27.             else if(request.responseText)
  28.             {
  29.                 $("hide_table").innerHTML = request.responseText;
  30.             }
  31.         }
  32.         -->
  33.         </script>

Ambos funcionan con esta linea

Código PHP:
Ver original
  1. $post['thanks'] = "<a href=\"\" onclick=\"return hideuntilthanks_reload();\">Recargar Beta </a><a id=\"a{$post['pid']}\" onclick=\"return thx({$post['pid']}); return hideuntilthanks_reload();\" href=\"showthread.php?action=thank&tid={$post['tid']}&pid={$post['pid']}\">
  2.             <img src=\"{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_thx.gif\" border=\"0\" alt=\"$lang->thx_main\" title=\"$lang->thx_main\" id=\"i{$post['pid']}\" /></a>";

Pero solo bajo onclick´s individuales, la idea es que un solo onclick (el que enlaza la imagen) realice ambos eventos

Saludos y disculpas porque de verdad no me manejo NADA en esto de AJAX y javascript