Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/03/2011, 00:58
Avatar de El_Metallick
El_Metallick
 
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 4 meses
Puntos: 16
Respuesta: Problema con JavaScript y php

lo que quieres hacer lo tienes que hacer con ajax, dado que el elemento algo toma valor sólo en tiempo de ejecución cuando se activa el evento, es decir, en el navegador del cliente y no en el servidor, luego necesitas hacer que una vez que se active el evento se haga un llamado al servidor y que este responda.

Prueba con esto:

Código Javascript:
Ver original
  1. function newAjax() {
  2.     var xmlhttp = false;
  3.    
  4.     try {
  5.         xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
  6.     } catch(e) {
  7.         try    {
  8.             xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  9.         } catch(E) {
  10.             if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  11.                 xmlhttp = new XMLHttpRequest();
  12.             }
  13.         }
  14.     }
  15.    
  16.     return xmlhttp;
  17. }
  18.  
  19. function clic(algo){
  20.         var variableJscript;
  21.  
  22.         var ajax = newAjax();
  23.  
  24.     ajax.open('GET', 'generateVal.php?algo='+algo, true);
  25.     ajax.onreadystatechange = function() {
  26.         if (ajax.readyState == 4) {
  27.             alert('llamada a funcion Php desde Javascript : ' + ajax.responseText);
  28.         }
  29.     }
  30.    
  31.     ajax.send();
  32. }

y en generateVal.php

Código PHP:
Ver original
  1. <?php
  2. $algo = $_GET['algo'];
  3.  
  4. include_once 'prueba.php';
  5.  
  6. $obj = new prueba();
  7. echo $obj->respuesta($algo);
  8. ?>

Espero te ayude

Saludos
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!