A ver voy a intentar echarte una mano como yo lo haría, a ver si te sirve:
Javascript
:
Código HTML:
function GuardaFormulario()
{
var _TELEFONO = document.forms['form1'].elements['TELEFONO'];
if (_TELEFONO.value.length == 0)
{
alert("Insertar el Teléfono");
_TELEFONO.focus();
return 0;
}
else
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "valida1.php?TELEFONO=" + encodeURIComponent(_TELEFONO), true);
xmlhttp.send();
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var xml = xmlhttp.responseXML;
dato=xml.getElementsByTagName("datos");
if(dato[0].firstChild.nodeValue=="1")
{
num_user=xml.getElementsByTagName("numusuario");
var boton = confirm("¡Usuario existente!¿Desea hacer un nuevo registro?");
if (boton)
{
window.location.href = "menu3.php?id="+num_user[0];/////Aquí es donde no sé traer esta variable/////
}
else
{
window.location.href = "menu4.php";
}
}
if(dato[0].firstChild.nodeValue=="0")
{
alert("¡El Cliente se ha dado de alta!");
document.forms['form1'].submit();////Aquí mando el formulario si el teléfono no existe.
}
}
}
}
php
Código PHP:
<?php
header('Content-Type: text/xml');
header("Cache-Control: no-store, no-cache, must-revalidate");
$xml="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
$xml.="<respuesta>\n";
require_once('Connections/conexion.php');
$TELEFONO = isset($_GET['TELEFONO']) ? $_GET['TELEFONO']:"";
$query=mysql_query("SELECT TELEFONO,NUM_USUARIO FROM usuarios WHERE TELEFONO ='".$TELEFONO."'");
$rows = mysql_num_rows($query);
if ($rows>=0)
{
$assoc=mysql_fetch_assoc($query);
$xml.="<datos><![CDATA[1]]></datos>\n";
$xml.="<numusuario><![CDATA[".$assoc['NUM_USUARIO']."]]></numusuario>\n";
}
else
{
$xml.="<datos><![CDATA[0]]></datos>\n";
}
$xml.="</respuesta>\n";
?>
A ver si te sirve.
Ya me comentas algo.
Lo que hacemos es enviar los datos por php en modo xml y recogemos con javascript num_user=xml.getElementsByTagName("numusuario"); o dato=xml.getElementsByTagName("datos"); y leemos con num_user[0] o dato[0]
Salu2 ;)