shreyaskudav Posted May 14, 2014 Share Posted May 14, 2014 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! Link to comment Share on other sites More sharing options...
Ingolme Posted May 14, 2014 Share Posted May 14, 2014 One problem I see is that you've put 'this.value' between quotes, that means you're actually passing the string "this.value". But that's not the real problem. In order to figure out your problem you're going to have to print_r($_POST) to see what values it's getting. Link to comment Share on other sites More sharing options...
shreyaskudav Posted May 14, 2014 Author Share Posted May 14, 2014 (edited) Thnks It worked somehow! dunno how?? ! Edited May 14, 2014 by shreyaskudav Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now