PDA

View Full Version : Reading AJAX data



cmccully
18 Sep 2010, 01:07 PM
Hi all,


I have an AJAX script that pulls a radio group list from PHP. I would like to then read which of those options the user subsequently selects.

My AJAX script:

function showCharacteristics()
{
xmlhttp1=new XMLHttpRequest();
xmlhttp1.onreadystatechange=function()
{
if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
{
document.getElementById("charList").innerHTML=xmlhttp1.responseText;
}
}
xmlhttp1.open("GET","ctrPanelProc.php?selection=getCharacteristics",true);
xmlhttp1.send();
}

My PHP script:

$sql = "SELECT * FROM characteristic ORDER BY characteristic ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<input type='radio' name='charID' value='" . $row['characteristicID']
. "'/> " . $row['characteristic'] . "<br />" ;
}

I would like to be able to read the 'charID' value the user has selected and pass that to another function. How can I access this value? Thanks!


cmccully

chintan
19 Sep 2010, 03:01 AM
do you want to get value on ' Onclick' of radio?
If so then you have to call function on your php page to get value.
echo "<input type='radio' name='charID' Onclick="your function()" id=charID[] value='" . $row['characteristicID']
. "'/> " . $row['characteristic'] . "<br />" ;
Fuction will contain the code

var val=document.getElemenById('charID').value;