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

时间:2014-08-19 10:22:59

标签: c# javascript php html web-services

这是我的代码

<?

$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列表框中txt文件中的单词。我对所选值的显示有疑问。它的输出只显示一个选择框,其中包含文本文件中的单词。现在我想显示所选单词。如果我从列表框中选择了选项,那么我可以显示并为每个单词分配任务。

请帮我在同一页面中显示所选单词。或其他页面(发布方法)。

1 个答案:

答案 0 :(得分:1)

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>