Ver Mensaje Individual
  #6 (permalink)  
Antiguo 08/05/2012, 11:24
sjj
 
Fecha de Ingreso: octubre-2008
Mensajes: 213
Antigüedad: 15 años, 6 meses
Puntos: 12
Respuesta: Menú select con respuestas diferentes

Ahí armé algo con PHP y Javascript. Este código funciona perfectamente y me trae los países como necesito. El único problema que tengo ahora es que tuve que poner la información para que me la devuelva en forma de cadena de texto. Yo necesitaría que la respuesta en lugar de ser un texto, sea un menú select. Les dejo lo que armé por si es de ayuda o a alguien le sirve:

pagina 1.html

Código HTML:
<html>
<head>
<title>Problema</title>
<script src="funciones.js" language="JavaScript"></script>
</head>
<body>
<h3>Seleccione su país de residencia.</h3>
<div id="menu">
<p><a id="enlace1" href="pagina1.php?cod=1">Argentina</a></p>
<p><a id="enlace2" href="pagina1.php?cod=2">Resto del Mundo</a></p>
</div>
<div id="detalles">Seleccione su signo.</div>
</body>
</html> 
pagina 1.php

Código PHP:
<html>
<head>
<title>Problema</title>
<script src="funciones.js" language="JavaScript"></script>
</head>
<body>

<?
if ($_REQUEST['cod']==1)
  echo 
"Las provincias en que ofrecemos nuestros servicios son Buenos Aires, Córdoba, La Pampa y Santa Fe";
if (
$_REQUEST['cod']==2)
  echo 
"Los países en que ofrecemos nuestros servicios son Brasil, Bolivia, Chile, Paraguay y Uruguay";
 
?>

</body>
</html>
funciones.js

Código:
addEvent(window,'load',inicializarEventos,false);

function inicializarEventos()
{
  var ob;
  for(f=1;f<=2;f++)
  {
    ob=document.getElementById('enlace'+f);
    addEvent(ob,'click',presionEnlace,false);
  }
}

function presionEnlace(e)
{
  if (window.event)
  {
    window.event.returnValue=false;
    var url=window.event.srcElement.getAttribute('href');
    cargarPais(url);     
  }
  else
    if (e)
    {
      e.preventDefault();
      var url=e.target.getAttribute('href');
      cargarPais(url);     
    }
}


var conexion1;
function cargarPais(url) 
{
  if(url=='')
  {
    return;
  }
  conexion1=crearXMLHttpRequest();
  conexion1.onreadystatechange = procesarEventos;
  conexion1.open("GET", url, true);
  conexion1.send(null);
}

function procesarEventos()
{
  var detalles = document.getElementById("detalles");
  if(conexion1.readyState == 4)
  {
    detalles.innerHTML = conexion1.responseText;
  } 
  else 
  {
    detalles.innerHTML = 'Cargando...';
  }
}

function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}