I am writing a simple code to select a radio button and pass the value of the selected radio to php code, through ajax!
Heres my code for ajax:
function sendid(attack){var att;var xmlhttp;if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){document.getElementById("result").innerHTML=xmlhttp.responseText;}}xmlhttp.open("POST","battlephp.php",true);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send("att="+attack+"");}</script></head><body><input type="radio" value="10" name="attack" onclick="sendid('this.value')"/> Attack 1<input type="radio" value="20" name="attack" onclick="sendid('this.value')"/> Attack 2
And my php code:
$attack = intval($_POST['att']);echo "Working ".$attack;
And the Error I am getting is:
( ! ) Notice: Undefined index: att in C:wampwwwbattlephp.php on line 5Call Stack# Time Memory Function Location1 0.0003 247432 {main}( ) ..battlephp.php:0Working 0
Surely its not identifing the att which is pass through the ajax..! But how should I handle it now?? I am newbie to ajax!