简体   繁体   English

PHP ComboBox在其他页面上显示所选值

[英]PHP ComboBox display selected value on other page

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: 第1页上的代码:

<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: 第2页上的代码:

<?php

  echo $_POST['Make'];

?> ?>

And instead of show the selected option like '1º' it shows the option value 'ano_1' 而不是显示所选的选项(如“1º”),而是显示选项值“ 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. 但是,有了12个选项,它将变得相当大。

<?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. 也许有一种更有效的方法-但我仍然是php新秀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM