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();
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.