javascript - 如何自动提交带有文本框 onchange 值的表单?
问题描述
<html>
<head></head>
<body>
<div class="col">
<form action="#" method="post">
<select id="periodname" class="drpdwn" value=" " onchange='myFunction()'>
<?php foreach($period as $period): ?>
<option><?= $period['period']; ?></option>
<?php endforeach; ?>
</select>
</form>
</div>
<div class="col" style="width:200px">
<form action="myprofile.php" method="post" name='periodGet' id='periodGet'>
<input name='periodText' autocomplete="off" value="Period">
<input type="submit" value="Go">
</form>
</div>
</body>
</html>
这是我整个系统的一部分,我问如果文本框值发生更改而不按提交按钮或输入按钮,如何自动提交表单谢谢
解决方案
您不需要任何函数来触发选择值的 onchange()。You can simply submit the form when the select value is changed using this.form.submit()
in onchange()
function as an example below.
<select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>
$("#textF").keyup(function() {
console.log($("#textF").val());
$('#form2').delay(200).submit();
});
$("#textF2").change(function() {
console.log($("#textF2").val());
$('#form2').delay(200).submit();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="path1">
<select id="periodname" class="drpdwn" value=" " onchange='this.form.submit()'>
<option>test1 </option>
<option>test2 </option>
<option>test3 </option>
</select>
</form>
<form action="path2" id="form2">
<input type="text" id="textF" placeholder="onkeyup()">
<input type="text" id="textF2" placeholder="onchange()">
</form>
推荐阅读
- amazon-web-services - 使用内存利用率自动缩放,警报指标处于数据不足状态
- java - Circle Layer Mapbox - 在geojson(Java)中传递点数
- github-actions - GitHub 操作失败:意外标记 `)' 附近的语法错误
- ssl - 春季启动HTTPS-TLS
- javascript - 这个和父元素
- python - python函数参数是通过引用传递的吗?
- python - 视图集和路由器是否绝对必要(特别是在嵌套序列化程序的情况下)?
- typescript - 如何通过索引访问映射类型
- r - 不是斜体标签 ggplot2 中只有一个单词
- powerbi - 如何计算 power bi 度量中的日期差异?