Jump to content

passing a variable.


n00bert

Recommended Posts

I can't seem to pass my cid variable to my getPage() function. But here I think it will be easier to help if you can see what i'm talking about so here is my function.

 

function getPage(intPage){
var xmlHttp;
try{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}
catch (e){
	// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){
			window.location="noajax.html";
			return false;
		}
	}
}
xmlHttp.onreadystatechange=function(){
	if(xmlHttp.readyState==4){
		document.getElementById('content').innerHTML=xmlHttp.responseText;
	}else{
		document.getElementById('content').innerHTML='<center><img src="images/loading.gif" alt="Loading" style="border:0px;"/><br />Loading, Please Wait...</center>';
	}
}
switch(intPage){
	case 1:
		xmlHttp.open("GET","news.php",true);
		xmlHttp.send(null);
	break;
	case 2:
		xmlHttp.open("GET","about.php",true);
		xmlHttp.send(null);
	break;
	case 3:
		xmlHttp.open("GET","viewgallery.php",true);
		xmlHttp.send(null);
	break;
	case 4:
		xmlHttp.open("GET","services.php",true);
		xmlHttp.send(null);
	break;
	case 5:
		xmlHttp.open("GET","contact.php",true);
		xmlHttp.send(null);
	break;
	case 6:
		xmlHttp.open("GET","parts.php",true);
		xmlHttp.send(null);
	break;
	case 7:

	default:
		xmlHttp.open("GET","news.php",true);
		xmlHttp.send(null);
}
}

 

and here is the link i'm trying to pass

 

<a href='javascript:getPage(3)?cid=".$row[0]."'>".$row[1]."</a>

 

I'm pretty new to javascript and ajax...too be honest i'm still unsure on what ajax is.

 

sry if i left out any key details. I'm pretty tired right now. So just let me know if you need anything else to help.

 

thanks,

n00b

 

Link to comment
https://forums.phpfreaks.com/topic/124912-passing-a-variable/
Share on other sites

Try this script

 

<script type="text/Javascript">
  var xmlHttp;
    try{	
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
    }catch (e){
      // Internet Explorer
      try{
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }catch (e){
         try{
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }catch (e){
	window.location="noajax.html";
	return false;
}
   }
}

function pageRequest(page){
    xmlhttp.open('GET', page);
    xmlHttp.onreadystatechange=function(){	
    if(xmlHttp.readyState==4){
        document.getElementById('content').innerHTML=xmlHttp.responseText;
    }else{
document.getElementById('content').innerHTML='<center><img src="images/loading.gif" alt="Loading" style="border:0px;"/><br />Loading, Please Wait...</center>';
    }
  }
  xmlhttp.send(null);
}
</script>

 

Just use the GET method by adding the value to the page name

 

EXAMPLE

 

news.php?value=4

<a href='javascript:pageRequest("news.php?value=4")'>

 

From the file use

 

<?Php

  echo $_GET['value'];

?>

 

to get the value

 

Link to comment
https://forums.phpfreaks.com/topic/124912-passing-a-variable/#findComment-646738
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.