Passing Js Variable To Php Variable
I want to pass the id value of the tag that has just been clicked to a php file that is being loaded onto the page using greybox. I got the id stored in a js variable called link
Solution 1:
var myCallback = function(caller){
var linkID = caller.id;
var xmlhttp = newXMLHttpRequest();
xmlhttp.open("POST","species/butterfly.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("linkID="+linkID;);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert("Request complete. Data: "+xmlhttp.responseText);
}
};
alert(linkID);
}
EDIT:
Pure GreyBox:
var myCallback = function(caller){
var linkID = caller.id;
caller.href = "species/butterfly.php?linkID="+linkID;
}
Solution 2:
This will convert js variable to php variable
<script>functionsud(){
javavar=document.getElementById("text").value;
document.getElementById("rslt").innerHTML="<?php$phpvar='"+javavar+"';
echo$phpvar.$phpvar;?>";
}
function sud2(){
document.getElementById("rslt2").innerHTML="<?phpecho$phpvar;?>";
}
</script><body><divid="rslt"></div><divid="rslt2"></div><inputtype="text"id="text" /><buttononClick="sud()" >Convert</button><buttononClick="sud2()">Once Again</button></body>
Post a Comment for "Passing Js Variable To Php Variable"