setting target page using javascript

In the following example, the form’s action property is set dynamically using javascript. This method can help in setting the target page to which form should submit data on the run time.

<!DOCTYPE html>
<html>
<head>
    <title>Untitled document</title>
  <meta charset="utf-8" />

    <script language="javascript" type="text/javascript">

        function myfunction(actionvalue)
        {
            var myform = document.getElementById("frm");
            myform.action = actionvalue;
            // document.write(myform.method);
            // myform.reset();

             myform.submit(); 

        }
    </script>
</head>
<body>

<form id="frm" name="frm" method="post" action="about.html">

    <input id="txtname" name="txtname" type="text" />
    <input id="btn1" name="btn1" type="button" 
           value="Form1Data.html" onclick="myfunction('form1data.html');" />

    <br /><br />

    <input id="btn2" name="btn2" type="button"
           value="Form2Data.html" onclick="myfunction('form2data.html');" />

    <br /><br />

    <input id="btn3" name="btn3" type="reset"
           value="Reset" />

</form>

</body>
</html>

 

 

Add a Comment

Your email address will not be published. Required fields are marked *