Jump to content

passing an input box (of type hidden)'s value to a ajax along with radiobutton


bindiya

Recommended Posts

This topic was pasted in php forum becoz i didnt know this comes in ajax also. When i got the reply to post in ajax forum, i am posting my problem in ajax forum.Sorry for the double post. SORRY.

 

In my php page ,the 5 datas are taken from the database table.

3 among them are displayed in a radio button value,and one is displayed as a value in the input field of type hidden .

I need to pass these hidden value  along with the  selected radio button value to the ajax script

Is it possible to do this

 


$q="select * from questions where id=(select max(id) from  questions)";
$r=mysql_query($q);
$row=mysql_fetch_row($r);
$poll_id = $row['id'];
$question=$row['question'];
[color=red]echo "<input type='hidden' name='question' id='question'  value=$question>";[/color]//this value is the one to be passed to ajax function
echo "<tr><td>$row[1]</td></tr>".
"<tr><td><input type='radio' value='1' name='answer' id='answer' onclick='getVote(this.value)'>$row[2]</td></tr>".
"<tr><td><input type='radio' value='2' name='answer' id='answer' onclick='getVote(this.value)'>$row[3]</td></tr>".
"<tr><td><input type='radio' value='3' name='answer' id='answer' onclick='getVote(this.value)'>$row[4]</td></tr>".
"<tr><td><input type='radio' value='4' name='answer' id='answer' onclick='getVote(this.value)'>$row[5]</td></tr>".
"</table>";

------------ajax function
function getVote(int)
{
var quest= document.getElementById['question'].value ;
//alert(quest);
var params = "vote=int&q=quest";
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5&         +"&question="+q
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("poll").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","abc.php? "+params,true);
xmlhttp.send();
}

Since $question has a unique value and your writing the page in php why not just add it to the params value:

 

var params = "vote=int&q="+<?php echo $question ?>;

 

think that's where it goes.

 

Or just run a query for it in abc.php.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.