a.jsp页面有两个控件分别为 branchCD,productCD.想实现点击更新按钮(或超连接),在branchCD,productCD都不为空时跳转到b.jsp并传递branchCD,productCD两个参数,否则提示branchCD,productCD都不能为空

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <script language="javascript" type="text/javascript">
    function subControl(){
    if(document.getElementsByName("branchCD")[0].value == ""){
    alert("branchCD is empty!");
    return false;
    }else if(document.getElementsByName("productCD")[0].value == ""){
    alert("productCD is empty!");
    return false;
    }
    document.getElementsByName("aa")[0].action="b.html&branchCD="+form.branchCD.value+"&productCD="+form.productCD.value;
    }
      </script>
     </HEAD> <BODY>
           <input type="text" name="branchCD" /><br/>
     <input type="text" name="productCD"/><br/>
     <a href="b.html" name="aa" method="post" target="_blank" onclick="return subControl()">submit</a>
     </BODY>
    </HTML>
      

  2.   

    用JS来写,点击的时候判断,符合条件跳转:代码简略如下:<script>
      function gog(){
       var name = name.value;
       var psw = psw.value;
       if(name!=null && name !=''){
         if(psw!=null && psw !=''){
            window.location="b.jsp";
             }else alert('密码不能为空!');
         }else alert("姓名不能为空!");    }
    </script><input type="text" id = "name" >
    <input type="text" id="psw">