13
15

More than 5 years have passed since last update.

【JavaScript】1つのFormで送信先URLを複数設定する方法

Posted at

【目的】

・クリックするボタンによって遷移する画面を変えたい

【実装方法】

①<head>の中に以下のscriptを記載

form.jsp
<head>
<script type="text/javascript">
    function goServletB(){
        document.getElementById('form').action="ServletBのパス";
    }

    function goServletC(){
        document.getElementById('form').action="ServletCのパス";
    }
</script>
</head>

②<body>の中に以下のhtmlを記載

form.jsp
<body>
<form id='form' name='form' action="servletAのパス">
    <input type="submit" value="A" >
    <input type="submit" value="B" onclick="goServletB();" >
    <input type="submit" value="C" onclick="goServletC();>
</form>
</body>
13
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
15