this ajax function gets a textbox value and sends it to "response.php": (this is main function of ajax.js)
function ajaxFunction() {
var getdate = new Date();
if(xmlhttp) {
var txtname = document.getElementById("txtname");
xmlhttp.open("POST","response.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("txtname=" + txtname.value);
}
}
i am trying to add a radio button set to my form, so i changed this to:
function ajaxFunction() {
var getdate = new Date();
if(xmlhttp) {
var txtname = document.getElementById("txtname");
var radio = document.getElementById("radio2"); //ADDED
xmlhttp.open("POST","response.php",true);
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("txtname=" + txtname.value);
xmlhttp.send("radio=" + radio.value); //ADDED
}
}
and in response.php :
<?php
if (isset($_POST['txtname'])){
$radio = $_POST['radio'];
//process...
}
?>
input text still works but radio buttons not.
It may seem that your variable name is not “radio2” but “radio”.
Because you post the data by the name of “radio”.
—–ADDED MY ANSWER BELOW —-
And please try …
or
Because you can not use xmlhttp.send() twice.
I hope this helps you.