如何打开基于 HTML 表单条目的文件

发布于 2024-12-11 01:24:44 字数 1320 浏览 0 评论 0原文

我有两个带有下拉列表的单独字段,一个用于用户,第二个用于数据。然后我有一个按钮,理想情况下它可以作为两个下拉列表的选择的输出。该表单应检索与选择相关的文件。要打开的文件始终具有以下格式,因此我希望利用它: _.csv

这是我正在使用的简化版本:

<td align="left"><!-- User/data selector -->
  <table border="0">
    <tbody>
      <tr>
        <th align="left">User:</th>
        <td>
        <select name="users" id="users">
        <option value="user1">User 1</option>
        <option value="user2">User 2</option>
        <option value="user3">User 3</option>
        </select>
        </td>
      </tr>
      <tr>
        <th align="left">Data:</th>
        <td>
        <select name="data" id="data">
        <option value="data1">Data 1</option>
        <option value="data2">Data 2</option>
        <option value="data3">Data 3</option>                    
        </select>
        </td>
      </tr>
      <tr>
        <td></td>
        <td><input type='button' value='Generate Report' onClick='newWindow();'/></td>
      </tr>
    </tbody>
  </table>

所以,我正在努力解决的是知道在函数 newWindow() 获取所需的“用户”和“数据”选择以获取正确的文件。你能帮忙吗?

非常感谢!

I have two separate fields with a drop-down list, one is for User and the second Data. Then I have a button, which would ideally work as an output of the selection of the two drop-down lists. The form should retrieve the file that is relevant to the selection. The file to be opened has always the following format so I was hoping to make use of that: _.csv

Here's the simplified version of what I'm using:

<td align="left"><!-- User/data selector -->
  <table border="0">
    <tbody>
      <tr>
        <th align="left">User:</th>
        <td>
        <select name="users" id="users">
        <option value="user1">User 1</option>
        <option value="user2">User 2</option>
        <option value="user3">User 3</option>
        </select>
        </td>
      </tr>
      <tr>
        <th align="left">Data:</th>
        <td>
        <select name="data" id="data">
        <option value="data1">Data 1</option>
        <option value="data2">Data 2</option>
        <option value="data3">Data 3</option>                    
        </select>
        </td>
      </tr>
      <tr>
        <td></td>
        <td><input type='button' value='Generate Report' onClick='newWindow();'/></td>
      </tr>
    </tbody>
  </table>

So, what I'm struggling with is to know what to write in the function newWindow() to get the needed 'User' and 'Data' selection to get the correct file. Can you help?

Much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高冷爸爸 2024-12-18 01:24:44

您可以使用 document.getElementById(id).value 获取这些

openWindow 函数可能如下所示:

function openWindow(){
    var users = document.getElementById('users').value;
    var data = document.getElementById('data').value
    var fileName =  users + "_" + data + ".csv";
    var pathToFiles = "/whateverdirectory/";

    window.open(pathToFiles + fileName, fileName);
}

另外,请记住您 不应该使用 用于布局,它们用于显示表格数据。建议使用

代替。

您可能还会发现此博客条目很有用: 使用 window.open方法

You could get the values of those <select> fields with document.getElementById(id).value, where id would be data or users, in order to make up the csv file name.

The openWindow function could look like:

function openWindow(){
    var users = document.getElementById('users').value;
    var data = document.getElementById('data').value
    var fileName =  users + "_" + data + ".csv";
    var pathToFiles = "/whateverdirectory/";

    window.open(pathToFiles + fileName, fileName);
}

Also, remember you shouldn't be using <table>s for layout, they're meant for displaying tabular data. It is recommended to use <div>s instead.

You might also find this blog entry useful: Using the window.open method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文