Javascript Form How to - Get form action property from the Form object








Question

We would like to know how to get form action property from the Form object.

Answer


<!-- ww  w . j av  a 2  s  . co  m-->
<html>
    <body>
    <script language="JavaScript">
    function getAction(){
         var actionValue = document.form1.action;
         document.form1.msg.value = "Your form was submitted to the following URL:\n " + actionValue;
    }
    </script>
    <form name="form1" action="http://www.java2s.com/cgi-bin/process.pl">
    Enter your street address:
    <input type="text" name="address" size="40">
    <br><br>
    <input type="button" value="Submit"onClick=getAction()>
    <br><br><br>
    <textarea name="msg" rows="5" cols="62"></textarea>
    </form>
    </body>
</html>

The code above is rendered as follows: