如何在同一页面上显示所选值

How to display selected value on same page

本文关键字:显示 一页      更新时间:2023-09-26

这是我的代码

<?
$your_file = "tmp1.txt";
   //open the file
   $read_your_file = @fopen($your_file, "r") or die ("Couldn't Access $your_file");
   //create a variable to hold the contents of the file
$contents_your_file = fread($read_your_file, filesize($your_file));
//array of file contents
$your_array = explode("'n",$contents_your_file);
//close the file
fclose($read_your_file);
//counts the number elements in the property_categories array
$num_elmnts_array = count($your_array) ;
//elements in the drop down list
//$drop_elmnts = 0;
//begin creating your dropdown menu...
$your_menu = "<select name='"list'">";  
//For loop to begin
for($counter = 0; $counter < $num_elmnts_array; $counter++){
   $your_menu .= "<option value='"$your_variable'">$your_array[$counter]</option>";
    //$counter++;
}
//end select menu
$your_menu .= "</select>";
?>

<p><b>Here is my Menu</b><br>
<? echo "$your_menu"; 
?>

这段代码帮助在html列表框中列出文本文件中的单词。我对所选值的显示有疑问。它的输出只是显示一个选择框,其中包含文本文件中的单词。现在我想显示选定的单词。如果我从列表框中选择了选项,那么我可以在每个单词上显示和分配任务。

请帮助我在同一页中显示选定的单词。或者另一个页面(post方法)

you are looking like this:
<script>
function getSelectedValue(theValue){
document.getElementById('pasteTheValue').innerHTML=theValue;
}
</script>
<?php
$your_file = "file.txt";
//open the file
$read_your_file = @fopen($your_file, "r") or die ("Couldn't Access $your_file");
//create a variable to hold the contents of the file
$contents_your_file = fread($read_your_file, filesize($your_file));
//array of file contents
$your_array = explode("'n",$contents_your_file);
//close the file
fclose($read_your_file);
//counts the number elements in the property_categories array
$num_elmnts_array = count($your_array) ;
//elements in the drop down list
//$drop_elmnts = 0;
//begin creating your dropdown menu...
$your_menu = "<select name='"list'" onchange='"getSelectedValue(this.value)'">";  
//For loop to begin
for($counter = 0; $counter < $num_elmnts_array; $counter++){
   $your_menu .= "<option value='"$your_array[$counter]'">$your_array[$counter]    </option>";
    //$counter++;
}
//end select menu
$your_menu .= "</select>";
?>
<p><b><?php echo "$your_menu"; ?></b><br>
<p id="pasteTheValue"></p>