如何打开基于 HTML 表单条目的文件
我有两个带有下拉列表的单独字段,一个用于用户,第二个用于数据。然后我有一个按钮,理想情况下它可以作为两个下拉列表的选择的输出。该表单应检索与选择相关的文件。要打开的文件始终具有以下格式,因此我希望利用它: _.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
document.getElementById(id).value
获取这些openWindow
函数可能如下所示:另外,请记住您 不应该使用
用于布局,它们用于显示表格数据。建议使用
代替。
您可能还会发现此博客条目很有用: 使用 window.open方法。
You could get the values of those
<select>
fields withdocument.getElementById(id).value
, whereid
would bedata
orusers
, in order to make up the csv file name.The
openWindow
function could look like: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.