Here is an html form. I want to print the value of button selected. I have tried some code but it is not working.
HTML
<form method='post' name="letter" >
<input type='submit' name='A' value='A'/><br/>
<input type='submit' name='B' value='B'/><br/>
<input type='submit' name='G' value='G'/><br/>
</form>
PHP
<?php
$selected_val='';
if(isset($_GET['letter'])){
$selected_val = $_GET['letter'];
}
echo $selected_val;
?>
Set same name for all the submit button
HTML
<form method='post' name="letter" >
<input type='submit' name='getValue' value='A'/><br/>
<input type='submit' name='getValue' value='B'/><br/>
<input type='submit' name='getValue' value='G'/><br/>
</form>
Get the value with button name
PHP
<?php
$selected_val='';
if(isset($_POST['getValue'])){
$selected_val = $_POST['getValue'];
}
echo $selected_val;
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.