表单分向提交(javascript提交表单)

同一个表单可以根据用户的选择,提交给不同的后台处理程序。( 一个jsp页面中多个提交按钮提交不同的页面)即,表单的分向提交。如,在编写论坛程序时,如果我们希望实现用户在发送贴子的时候,既发送提交功能又有预览功能时,就会遇到上述问题。

<span style="font-size:24px;">登录注册页面:</span>  
form action="LoginServlet" name="loginform" method="post">  
         <h2 align="center" style=" font-family:隶书">欢迎登陆网上书店系统</h2><br>           
       <table align="center" style="border:1px solid">  
         <tr>  
            <td><font color="blue"><b>账 号:</b></font></td>  
            <td><input name="id" type="text"> </td>  
         </tr>  
         <tr>  
            <td><font color="blue"><b>密 码:</b></font></td>  
            <td><input name="password" type="password" size="20"> </td>  
         </tr>  
         <tr>  
            <td></td>  
            <td><input type="button" value="登  录" onclick="login()">  

             <input type="button" value="立即注册" onclick="register()">    
            </td>            
         </tr>  
       </table>            
     </form>  
<script type="text/javascript">  
     function login(){  
          if(document.loginform.id.value==""){  
            window.alert("账号不能为空!");  
            return ;  
          }  
          if(document.loginform.password.value==""){  
            window.alert("密码不能为空!");  
            return ;  
          }  
          loginform.submit();  
     }  
      function register(){  
          document.loginform.method="post";  
          document.loginform.target="rightframe";  
          document.loginform.action="register.jsp";  
          document.loginform.submit();  
      }  

  </script>  

主要是立即注册的按钮,要提交到register.jsp,所以可以用javascript临时改变 表单的属性值。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值