javascript - JavaScript 中的警报功能不起作用

标签 javascript forms asp-classic alert

我有一个用 classic asp 创建的旧页面,包含一个表单,在检查表单中的可用值后,我尝试使用 JavaScript 函数提交表单。

HTML:

<form method="POST" action="vendorCheckDates.asp" name="Searchform" id="submit_Form">
    Select Type of Search: </b>
    <select size="1" name="Query" class="button">
        <option selected name="vNAME" value="vNAME"> Name</option>
        <option name="vNUM" value="vNUM"> Number</option>
        <option name="vEM" value="vEM">Email </option>
        <option name="vFAX" value="vFAX">Fax </option>
    </select>
    <b>:</b>
    <input type="text" name="hsearch" id="hsearch">
    <fieldset class="fieldset">
        <legend><strong>Type</strong></legend>
        <input type="radio" value="gov" name="tType" >Gov
        <input type="radio" value="gfos" name="tType">GFOS
    </fieldset>
    <input type="button" value="Search" name="hfind" Onclick="SubmitForm()">
</form>

功能

function SubmitForm() {
    var hsearch = document.all.submit_Form.hsearch.value;            
    var tType = document.getElementById('tType').value;            
    if ((hsearch = ! '') && (hsearch = ! null)) {               
        if ((tType = ! '') && (tType = ! null)) {
            document.all.submit_Form.submit();
        } else { alert("please select search type");}
    } else { alert("please write search criteria"); }
}

当我运行表单时,字段 hsearch 为空,但是当我单击提交时,该值将为 true,这很奇怪,因为我仍然没有在输入字段 hsearch 中写入任何内容,这就是为什么 JavaScript 函数中的 sels 部分不起作用

最佳答案

我认为您使用了错误的运算符。应该是

 if ((hsearch != '') && (hsearch != null)) {               
        if ((tType != '') && (tType != null)) {

关于javascript - JavaScript 中的警报功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24402754/

相关文章:

sql-server - 查找SQLserver登录错误的来源

javascript - 输入文本的高亮部分

php - html 表单输入 DOM 引用的意外输出

PHP 后期计算

asp-classic - ASP 脚本未运行

asp-classic - vbscript:带参数的getref

javascript - Chart.js - 具有线性笛卡尔(数字)X 轴的条形图?

javascript - Protractor 测试不一致地通过/失败

javascript - 在websocket中,如何防止缓慢的异步响应数据错误修改

c# - FormClosing 和 FormClosed 事件不起作用