I am trying to access the javascript variable value from this code to ajax code
I tried to access like this but it is not working-
javascript code
<script type="text/javascript">
function getResults()
{
var radios = document.getElementsByName("address");
for (var i = 0; i < radios.length; i++)
{
if (radios[i].checked)
{
var a = radios[i].value
break;
}
}
}
function remove(a)
{
alert(a);
if(a=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","theaterdel.php?q="+a,true);
xmlhttp.send();
}
</script>
In this code I am trying to access the variable a's value from getResults() function to remove() like this
remove(a)
{}
But it is not working, when I alert a's value inside remove(a){}, it is printing undefined