【问题标题】:How to display selected value on same page如何在同一页面上显示选定的值
【发布时间】:2014-08-19 10:22:58
【问题描述】:

这是我的代码

<?

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

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

【问题讨论】:

  • 在下一页: if(isset($_POST['list'])) echo $_POST['list'];

标签: c# javascript php html web-services


【解决方案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>

【讨论】:

  • 谢谢妈妈。有用。在这里您提到 pasteTheValue 是从列表框中选择的值。我可以在 JSP 中使用它吗?像 运行 shell 脚本。
猜你喜欢
  • 1970-01-01
  • 2019-12-09
  • 2018-03-15
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多