意思不明确,只好瞎猜了,下面是一个验证文本框是否为空的例子,如果空则不提交<html>
<script language="javascript">
function test(e)
{
if(e.T1.value == "")
{
alert("文本框不能为空!");
return false;
}
return true;
}
</script>
<body><form method="POST" action="af.htm" onsubmit = "return test(this);">
  <input type="text" name="T1" size="20"><input type="submit" value="提交" name="B1"></p>
</form>
</body>
</html>

解决方案 »

  1.   

    未测试:
    for(iIndex=0;iIndex<document.forms[0].elements.length;iIndex++)
    {
    if(document.forms[0].item(i).tagName=="input")
    {
    if(document.forms[0].item(i).type=="text")
    {
    //document.forms[0].item(i).value;
    }
    }
    }
      

  2.   

    已经测试通过
    <script>
    function GetItem()
    {
    for(iIndex=0;iIndex<document.forms[0].elements.length;iIndex++)
    {
    if(document.forms[0].item(iIndex).tagName=="INPUT")
    {
    if(document.forms[0].item(iIndex).type=="text")
    {
    window.confirm(document.forms[0].item(iIndex).value);
    }
    }
    }
    }
    </script>
    <form>
    <input type=text id="T1" value="">
    <input type=text id="T2" value="">
    <input type=text id="T3" value="">
    <input type=button id="B1" value="效验" onclick="GetItem();">
    </form>
      

  3.   

    <form name="testfrom" onsubmit="return chk()">  //只需要在此加入提交时的动作
        <input type="text" name=testinput>
    </from>
    function chk()//检验
    {
       if (document.all.testinput.value=="")
       {
             alert("文本框为空")
             return false  //为空返回假
       }
      return true  //返回真
    }
      

  4.   

    在 gjd111686(数字金刚)的代码的基础上加了一下工,能效验其中某些文本框了^_^
    <script>
    function GetItem(str)
    {
    var a = new Array();

    for(var i = 0;i<(str.length+1)/2;i++)
    {
    a[i] = str.charAt(2*i)-1+1;
    alert("check "+a[i]);
    if(document.forms[0].item(a[i]).tagName=="INPUT")
    {
    if(document.forms[0].item(a[i]).value=="")
    {
    alert(document.forms[0].item(a[i]).id + " is null!");
    }
    }
    }
    }
    </script>
    <form>
    <input type=text id="T0" value="">
    <input type=text id="T1" value="">
    <input type=text id="T2" value="">
    <input type=button id="B1" value="&ETH;§&Ntilde;é" onclick="GetItem('0,2');">
    </form>