程序中用4个<input type ="text"name="name1">
怎么实现监听第三个text框,假如有值我就转向query2.jsp(条件只有text3一个框有值才转向query2.jsp)
假如第3个text框有值,在加上其他一个text框值那么就提交就真接提交到我的form 的Action

解决方案 »

  1.   

    <input type ="text"name="name1" id="1">
    <input type ="text"name="name1" id="2">
    <input type ="text"name="name1" id="3">
    <input type ="text"name="name1" id="4">window.onload = function(){
        var input3 = document.getElementById('3');
        if(input3.value != ""){
            //然后你就提交~··
        }
    };
      

  2.   

    首先你要保证有3个text,每个name都是"name1",条件是不是只有第三个text有值,其他都为空?
    var txts=document.getElementsByName("name1");
    if(txts.length>1){
      if(txts[2].value!=""&&txts[0].value==""&&txts[1].value==""){
      //页面转向代码
      }
    }
      

  3.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){
    var oInputs = document.getElementsByName('name1');
    var oButton = document.getElementById('click');
    var Result = "";
    var oArray = [];
    oButton.onclick = function(){
    for(var i = 0; i < oInputs.length; i++){(function(obj,i){
    oArray.push(obj);
    if(i == 2 && obj.value != ""){ //只有第三个文本框有值才提交
    for(var i = 0; i < oArray.length; i++){
    Result += oArray[i].value + "";
    Result += i + 1 == 3?oInputs[3].value:"";
    }
    document.forms[0].submit();
    }
    }(oInputs[i],i))

    }
    }

    };
    </script>
    </head><body>
    <form action="" name="tijiao">
    <input type ="text"name="name1"> 
    <input type ="text"name="name1"> 
    <input type ="text"name="name1"> 
    <input type ="text"name="name1">
    <input type="button" id="click" value="click" /> 
    </form>
    </body>
    </html>
      

  4.   

    是监听还是把text3作为一个判断条件??
    监听的话可以用onload
    作为判断条件的话,可以在提交的时候做判断
    不管是哪种情况,逻辑是一样的,

    只有text3一个框有值 转向query2.jsp;否则 提交
      

  5.   

    可能是我没说明白
      就是当第3个框有值的话就就提交到query2.jsp
      当其他有值 的话我就提交到 <form action="insert.do">
    那位修改下本人才接触js<script>
    function run()
    {
     var input1 = document.getElementById('id1'); 
     var input2 = document.getElementById('id2');
     var input3 = document.getElementById('id3');
     var input4 = document.getElementById('id4');  alert(input1);
     alert(input2);
     alert(input3);
     alert(input4);
     
     if((input1=="")&&(input2=="")&&(input3=="")&&(input4!=""))
    {
     window.open("query2.jsp");
     alert("oper");
     
    }
     else
    {
    return true;
     }
    }
    </script>
      

  6.   

    alert(input1);
    alert(input2);
    alert(input3);
    alert(input4);
    怎么都是object类型
     <input type="text" name="textname" size="15"id="id4" />
    难道这个没取到值吗?
      

  7.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){
    var oInputs = document.getElementsByName('name1');
    var oButton = document.getElementById('click');
    var Result = "";
    var oArray = [];
    oButton.onclick = function(){
    for(var i = 0; i < oInputs.length; i++){(function(obj,i){
    oArray.push(obj);
    if(i == 2 && obj.value != ""){ //只有第三个文本框有值才提交
    for(var i = 0; i < oArray.length; i++){
    Result += oArray[i].value + "";
    Result += i + 1 == 3?oInputs[3].value:"";
    }
    document.forms[0].action = "query2.jsp";
    document.forms[0].submit();
    }else{  //其他提交到insert.do
    document.forms[0].action = "insert.do";
    document.forms[0].submit();
    }
    }(oInputs[i],i))

    }
    }

    };
    </script>
    </head><body>
    <form action="" name="tijiao">
    <input type ="text"name="name1"> 
    <input type ="text"name="name1"> 
    <input type ="text"name="name1"> 
    <input type ="text"name="name1">
    <input type="button" id="click" value="click" /> 
    </form>
    </body>
    </html>
    这样就成了~··
      

  8.   

    兄弟但name 都不能只是name1啊
    因为我在下个页码还要去接收值
    name不能同名
      

  9.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    window.onload = function(){
    var oInputs = document.getElementsByTagName('input');
    var oButton = document.getElementById('click');
    var Result = "";
    var oArray = [];
    oButton.onclick = function(){
    for(var i = 0; i < oInputs.length; i++){(function(obj,i){
    if(obj.type == 'text'){
    oArray.push(obj);
    if(i == 2 && obj.value != ""){ //只有第三个文本框有值才提交
    for(var i = 0; i < oArray.length; i++){
    Result += oArray[i].value + "";
    Result += i + 1 == 3?oInputs[3].value:"";
    }
    document.forms[0].action = "query2.jsp";
    document.forms[0].submit();
    }else if(i == 2 && obj.value == ""){
    document.forms[0].action = "insert.do";
    document.forms[0].submit();
    }
    }
    }(oInputs[i],i))
    }
    }

    };
    </script>
    </head><body>
    <form action="" name="tijiao">
    <input type ="text"name="1"> 
    <input type ="text"name="2"> 
    <input type ="text"name="3"> 
    <input type ="text"name="4">
    <input type="button" id="click" value="click" /> 
    </form>
    </body>
    </html>这样就成了  跟name无关了