I want to show the selected value from a combobox that is on one page, and then show it on other page, and it worked with this code:
Code on page1:
<form action = 'enviar.php' method = "POST">
<select required id = "cmbAno" name = "Make">
<option value="ano_1"> 1º </option>
<option value="ano_2"> 2º </option>
<option value="ano_3"> 3º </option>
<option value="ano_4"> 4º </option>
<option value="ano_5"> 5º </option>
<option value="ano_6"> 6º </option>
<option value="ano_7"> 7º </option>
<option value="ano_8"> 8º </option>
<option value="ano_9"> 9º </option>
<option value="ano_10"> 10º </option>
<option value="ano_11"> 11º </option>
<option value="ano_12"> 12º </option>
</select>
<script>
function run()
{
document.getElementById("srt").value = document.getElementById("cmbAno").value;
}
function up()
{
var dop = document.getElementById("srt").value;
}
</script>
Code on page2:
<?php
echo $_POST['Make'];
?>
And instead of show the selected option like '1º' it shows the option value 'ano_1'
You could take the value and re-translate it to the desired text. Something like the snippet below. With 12 options it will get pretty large, however.
<?php if($_POST['Make'] == "ano_1"){ $result = "1º"; }elseif{ ...Continue... } ?>
And then later - where you want to display the result:
<?php echo $result; ?>
This should do what you want. There may be a more efficient way - but I'm still a php rookie.
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.