[英]How to get the radio button value from php
i want to get the radio button value in php.The thing is i am having the drop down in one page, when i select some value from dropdown, it sends the value to ajax and php and from php page it is generating the radio button. 我想在php中获取单选按钮值。问题是我在一个页面中下拉菜单,当我从下拉列表中选择某个值时,它将值发送给ajax和php,并从php页面生成了单选按钮。
Now i want to get the radio button value. 现在我想获取单选按钮的值。 How can i get it?
我怎么才能得到它?
code 码
index.php index.php
<script>
function showUser(str) {
if(str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gettheater.php?q="+str,true);
xmlhttp.send();
}
</script>
<div id="txtHint">
</div>
Code: gettheater.php 代码:gettheater.php
<?php
$q = strtolower(trim($_GET["q"]));
try {
$dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = 'SELECT address FROM theater WHERE LOWER(theater_name) = :q';
$sth = $dbh->prepare($sql);
$sth->bindValue(':q', $q);
$sth->execute();
echo "<form name='theater' method='POST'>";
echo "<table border='0' class='tabs'><tr><th>Theater Address</th><th>Select</th></tr>";
while($row = $sth->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td class='ad'>" . $row['address'] . "</td>";
echo "<td>";
echo '<input type="radio" name="address" value="43" />';
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
$dbh = null;
?>
from a pure javascript point you can grab all the radio boxes with the name address
and find the one that is selected. 从纯JavaScript的角度出发,您可以抓住所有带有名称
address
的单选框,然后找到所选择的单选框。
function getSelectedValue() {
var addresses = document.getElementsByName('address');
for (var i=0; i < addresses.length; i++) {
if (addresses[i].checked) return addresses[i].value;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.