この ajax 関数は、テキストボックスの値を取得して に送信します"response.php"
: (これは のメイン関数です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);
}
}
フォームにラジオボタンセットを追加しようとしているので、これを次のように変更しました。
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
}
}
そして response.php で:
<?php
if (isset($_POST['txtname'])){
$radio = $_POST['radio'];
//process...
}
?>
入力テキストは機能しますが、ラジオ ボタンは機能しません。