Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查jsp页面上的任何文本框是否为空?_Jsp_Textbox_Submit - Fatal编程技术网

如何检查jsp页面上的任何文本框是否为空?

如何检查jsp页面上的任何文本框是否为空?,jsp,textbox,submit,Jsp,Textbox,Submit,我在jsp页面上有许多文本框。我想在提交时检查每个文本框是否为空。当我提交时,如果任何文本框是空的,则不允许提交到servlet页面。如何为多个文本框选中该选项 <script type="text/javascript"> function checkvalue() { var mystring = document.getElementById('uname').value; var mystring1 = document.getElementById

我在jsp页面上有许多文本框。我想在提交时检查每个文本框是否为空。当我提交时,如果任何文本框是空的,则不允许提交到servlet页面。如何为多个文本框选中该选项

<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }
<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }

函数checkvalue(){
var mystring=document.getElementById('uname').value;
var mystring1=document.getElementById('pass').value;
如果(!mystring.match(/\S/)&&!mystring1.match(/\S/))
{
警报(“不允许为空值”);
返回false;
}
其他的
{
警报(“正确输入”);
返回true;
}
}
我已经像上面那样尝试过javascript。我只是想知道如何减少多个文本框的代码?


<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }
<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }
函数checkvalue(){ var mystring=document.getElementById('uname').value; var mystring1=document.getElementById('pass').value; 如果(!mystring.match(/\S/)&&!mystring1.match(/\S/)) { 警报(“不允许为空值”); 返回false; } 其他的 { 警报(“正确输入”); 返回true; } }


我已经像上面那样尝试过javascript。我只想知道如何减少多个文本框的代码?

您可以使用提交按钮上的onclick事件,并删除表单标记中的action属性(如果有)。在onclick事件处理程序函数中,您可以使用..检查是否选中了所有复选框。。document.getElementById(“checkBoxId”).checked-返回true/false;验证后,您可以使用document.form['formId'].submit()在表单上进行提交

<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }
<script type="text/javascript">
    function checkvalue() { 
    var mystring = document.getElementById('uname').value;
    var mystring1 = document.getElementById('pass').value; 
    if(!mystring.match(/\S/) && !mystring1.match(/\S/))
        {
            alert ('Empty value is not allowed');
            return false;
        }
    else 
        {
            alert("correct input");
            return true;
        }
    }

如果您需要更多帮助,请告诉我。

只有Jquery验证和服务器端验证,但是如果您仍然想要实现自定义验证,那么您应该进行如下更改

function checkvalue() { 
var returnValue = true;
$(".TxtBox").each(function(el,ue){ 
    if(!$(ue).match(/\S/)
    {
         alert("Empty value is not allowed");
         returnValue = false;
    }
    return returnValue;
})
}

到目前为止你尝试了什么?在这里,你会找到完整的解释。谢谢你的帮助。你能告诉我,我必须检查javascript中的每个文本框吗??这将是很大的帮助。。。