当前位置: 代码迷 >> JavaScript >> JS传值给servlet的有关问题
  详细解决方案

JS传值给servlet的有关问题

热度:172   发布时间:2012-03-06 20:47:55.0
JS传值给servlet的问题
<%@   page   language= "java "   contentType= "text/html;   charset=UTF-8 "%>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
  <head>
    <title> Insert   title   here </title>
  </head>
  <body>
    <h1>
      Buy   or   Sell
    </h1>
    <form   action= "./Cortrol "   method= "post "   name= "form1 ">
      <table>
        <tr>
          <td>
            Name   :
          </td>
          <td>
            <input   type= "text "   name= "name ">
          </td>
        </tr>
        <tr>
          <td>
            Number   :
          </td>
          <td>
            <input   type= "text "   name= "number ">
          </td>
        </tr>
        <tr>
          <td>
            Price   :
          </td>
          <td>
            <input   type= "text "   name= "price ">
          </td>
        </tr>
      </table>
 
      <table>
        <td>
          <input   type= "hidden "   name= "action "   value= "buy ">
          <a   href= "# "   onclick= "document.form1.submit() "> Buy </a>
        </td>
        <td>
          <input   type= "hidden "   name= "action "   value= "sell ">
          <a   href= "# "   onclick= "document.form1.submit() "> Sell </a>
        </td>
        <td>
          <a   href= "# "   onclick= "document.form1.reset() "> Reset </a>
        </td>
      </table>
    </form>
  </body>
</html>

传递到servlet后   不管选sell还是buy,得到的action的值都是buy
有什么办法能我点那个就传那个到servlet呢????

------解决方案--------------------
试试看
<a href= "# " onclick= "document.form1.action= './Cortrol?action=buy ';document.form1.submit() "> Buy </a>
  相关解决方案