gpt4 book ai didi

javascript - 如果未选中复选框且文本字段不为空,则显示警报

转载 作者:行者123 更新时间:2023-12-03 10:53:25 25 4
gpt4 key购买 nike

当信息存储到数据库中时,我有这个表格。我有一个复选框和一个文本字段。任一选项都是必需的,但如果文本字段不为空,则很有可能应选中该复选框。因此,如果文本字段中有值并且未选中复选框,我想显示警报。我希望在点击“提交”按钮时出现此警报。这是我的表格:

<form id="form" name="form" action=?post=yes" method "post">
<input type="checkbox" name="close" id="close" value="Yes"><label for="close" title="Close this RMA">Close this RMA</label>
<label><input type="text" name="dateshipped" id="dateshipped"/></label>
<button type="submit">Save and Continue</button>
</form>

因此,如果未选中“close”复选框且“dateshipped”不为空,则在单击“提交”时显示警报。

谢谢。

最佳答案

您可以在提交按钮的 onclick 事件上调用 JavaScript 函数,如下所示

<button type="submit" onclick="callAfunction();">Save and Continue</button>

并定义函数

callAfunction()
{

//do the checks with: document.getElementById('close').value
// display an alert("a message");
}

关于javascript - 如果未选中复选框且文本字段不为空,则显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28350387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com