0
ページロード時に選択する必要があるラジオボタンが2つあります。 2番目はjavascriptを使ってラジオボタンidを最初のページに転送するphpです。上記のファイルにラジオボタンのIDを送信ラジオボタンがページ上に表示されないロードajax
<html>
<head>
<script language="javascript">
function checked_attemped(question_id)
{
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4)
{
var x = ajaxRequest.responseText;
alert(x);// It shows the radio button id (option1) which is transfered from checked_attempted_option.php
alert(document.getElementById(x)); // But it shows null
document.getElementById(x).checked=true; //Nothin Happen
document.getElementById(option1).checked=true; //This is working and radio button checked, but above line is not working. I want the above line work.
}
}
var queryString = "question_id=" + question_id;
ajaxRequest.open("GET", "checked_attempted_option.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
</head>
<body>
<script language="javascript">
window.onload=checked_attemped('1');
</script>
<input name="option1" id="option1" type="radio" value="option1">
</body>
</html>
これは、PHPファイルです
checked_attempted_option.php
$question_id=$_GET['question_id'];
$query="select * from question_attemped where question_id='$question_id'";
$result=mysql_query($query) or die(mysql_error());
$row=mysql_fetch_array($result);
echo $row['answer'];
も共有してください – brk
は、あなたの$ question_id後にこれを入れてくださいHTML:$ question_id = mysql_real_escape_stringの($ question_id)。それはあなたの問題への答えではなく、ちょうど助言 – Ciro
PHPスクリプトは値としてoption1を返す – swdpankaj