18
Tháng 11Lấy giá trị của Radio Button trong PHP
<input type="radio"> của HTML cho phép người dùng chọn một tuỳ chọn từ các lựa chọn cho trước. Sau đây là mã lệnh PHP để lấy giá trị được chọn từ <input type="radio"> của HTML đã cho.
Để lấy giá trị của radio button:
<form action="" method="post">
<input type="radio" name="radio" value="Radio 1">Radio 1
<input type="radio" name="radio" value="Radio 2">Radio 2
<input type="radio" name="radio" value="Radio 3">Radio 3
<input type="submit" name="submit" value="Get Selected Values" />
</form>
<?php
if (isset($_POST['submit'])) {
if(isset($_POST['radio']))
{
echo "Bạn đã chọn:".$_POST['radio']; // Hiển thị giá trị đã chọn
}
?>
Đánh giá