A-AA+then

ครับ ต้องการ เอาค่า จาก radio button โดย ajax ครับ ต้องทำไงครับ

2,355
<script language="JavaScript" language="JavaScript">
var req;
function callme()
{
//check();
try{

if(window.XMLHttpRequest)
req= new XMLHttpRequest();
else if(window.ActiveXObject)
req= new ActiveXObject("Microsoft.XMLHTTP");
else{
alert("Browser not Support");
return false;
}

}catch(ex){
alert('Error Ajax Handler Object ???');
}
req.onreadystatechange = statechange;

var str =Math.random();
var querystr="";
querystr+="searchFinal.php?pop="+str;
querystr+="&search="+document.formSearch.search.value;
querystr+="&name="+encodeURI(document.getElementById("name").value);
// alert(encodeURI(document.getElementById("name").value));
alert(querystr);
// req.open("GET",querystr,true);
// req.send(null);
}
function statechange()
{
if(req.readyState ==4)
{

var x=document.getElementById("area");
x.innerHTML=req.responseText;
//alert(req.responseText);
}
else
{
var x=document.getElementById("area");
x.innerHTML=req.responseText;
//alert(req.responseText);
x.innerHTML="<img src=images/indicator_big.gif>Please wait.....";
}
}
</script>


<form name="formSearch" >
<div id="area">555</div>
<table width="224" height="37" border="0" cellpadding="0" cellspacing="5">
<tr>
<td width="150">
<input type="text" name="search" id="search">
</td>
<td width="59">
<input type="button" name="Submit" value="search" onclick="callme();" >
</td>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="firstname" id="name" > First Name</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="lastname" id="name" > Family Name</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="email" id="name" > Email</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="affili" id="name" > Affiliation</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="all" id="name" > All</td><br>
</tr>
</table>
</form>

2 ความคิดเห็น

ลอง GForm มั้ย ง่ายๆ

<script type="text/javascript" src="http://www.goragod.com/js/gajax.js"></script>
<form name="formSearch"  id="formSearch" action="search.php" method="post">
<div id="area">555</div>
<table width="224" height="37" border="0" cellpadding="0" cellspacing="5">
<tr>
<td width="150">
<input type="text" name="search" id="search">
</td>
<td width="59">
<input type="submit" name="Submit" value="search" />
</td>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="firstname" id="name" > First Name</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="lastname" id="name" > Family Name</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="email" id="name" > Email</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="affili" id="name" > Affiliation</td><br>
</tr>
<tr>
<td><input align= "left" type="radio" name="name" value="all" id="name" > All</td><br>
</tr>
</table>
</form>
<script type="text/javascript">
new GForm('formSearch').onsubmit(function(xhr){
    alert(xhr.responseText);
});
</script>


อยากได้ element อะไรไรเพิ่มก็ใส่ลงไป ถ้าจะทดสอบ ให้สร้าง search.php ด้วย เพื่อรับค่าจาก ajax
<?php
  print_r($_POST);// เพื่อทดสอบดูค่าที่ส่งมา
?>
1

ขอบคุณ มากครับ นึกว่าจะไม่มีคนตอบแล้ว นั่งมั่วทั้งวันนนน+++
2
^