如何将具有 2 个选择的 HTML 表单更改为 Javascript?

发布于 2024-12-12 22:28:01 字数 666 浏览 2 评论 0原文

我正在使用以下 HTML 表单:

<form method = 'POST' action = '/python/stats/'>
<select name = 'team'>
<option value = 'team1'> team1 </option>
<option value = 'team2'> team2 </option>
<option value = 'team3'> team3 </option>
</select>
<select name = 'player'>
<option value = 'player1'> player1 </option>
<option value = 'player2'> player2 </option>
<option value = 'player3'> player3 </option>
</select>
<input type = 'submit' value = "Update">
</form>

操作 /python/stats 需要 2 个参数。我如何编辑这个表单(到javascript?)以便每次更改其中一个选择时都会调用该操作?

I am working with the following HTML form:

<form method = 'POST' action = '/python/stats/'>
<select name = 'team'>
<option value = 'team1'> team1 </option>
<option value = 'team2'> team2 </option>
<option value = 'team3'> team3 </option>
</select>
<select name = 'player'>
<option value = 'player1'> player1 </option>
<option value = 'player2'> player2 </option>
<option value = 'player3'> player3 </option>
</select>
<input type = 'submit' value = "Update">
</form>

The action /python/stats requires 2 parameters. How can I edit this form (to javascript?) so that the action is called each time either of the selects is changed?

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

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

发布评论

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

评论(1

在你怀里撒娇 2024-12-19 22:28:01

表单标记中的 action 属性指定将表单提交到的位置。要使用 onchange 事件执行此操作,您可以在该事件中执行表单提交。

<head>
<script type='text/javascript'>
function doSubmit(){
    document.forms["form1"].submit();
}
</script>
</head>


<form id='form1' method = 'POST' action = '/python/stats/'>
<select name = 'team' onchange='doSubmit();'>
<option value = 'team1'> team1 </option>
<option value = 'team2'> team2 </option>
<option value = 'team3'> team3 </option>
</select>
<select name = 'player' onchange='doSubmit();'>
<option value = 'player1'> player1 </option>
<option value = 'player2'> player2 </option>
<option value = 'player3'> player3 </option>
</select>
<input type = 'submit' value = "Update">
</form>

the action property in the form tag specifies the location to submit the form to. To do this with an onchange event is, you can do a form submit in the event.

<head>
<script type='text/javascript'>
function doSubmit(){
    document.forms["form1"].submit();
}
</script>
</head>


<form id='form1' method = 'POST' action = '/python/stats/'>
<select name = 'team' onchange='doSubmit();'>
<option value = 'team1'> team1 </option>
<option value = 'team2'> team2 </option>
<option value = 'team3'> team3 </option>
</select>
<select name = 'player' onchange='doSubmit();'>
<option value = 'player1'> player1 </option>
<option value = 'player2'> player2 </option>
<option value = 'player3'> player3 </option>
</select>
<input type = 'submit' value = "Update">
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文