Hey, I am having trouble sending a javascript variable to php at the moment.
I have div's which have id's on them then when I click on them I have it as onclick="getId(id)"
Then this is the code which is not working of course in sending the id to the php script
The page is called test.php.
<script type="text/javascript">
function getId(id)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?id="+id,true);
xmlhttp.send();
}
</script>
<?php
$q = $_GET['id'];
echo $q;
?>
<div id="2" onclick="getId(id)" style="cursor:pointer;border:1px solid black;background-color:#EDEDED;width:100px;">Why won't this work</div>
What I am wanting it to do is for the id to be an index in a php array which will contain the name of tables in a database to display.
Thanks.