Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change form submit action and then submit the form

I'm trying to add a button to my form that would essentially run some different php code than my regular form submission code, that would, instead of emailing me the form, convert my page into a nice pdf ready to print. I have everything working except that pressing the button is giving me an error.

Firebug says : enter image description here

Here's the code:

<form id="adaugareanunt" name="adaugareanunt" action="mailerPDF.php" method="post">
    <table width="535" border="0" cellspacing="2" cellpadding="3">
         <tr class="TrDark">
         //... more form code

and for the button:

<div style="text-align:right"><img src="images/print-button.png" onClick="chgAction()" width="60px" height="20px"></div>

with the script:

<script language="JavaScript" type="text/JavaScript">
    function chgAction()
        {
            document.getElementById["adaugareanunt"].action = "mailerXFDF.php";
            document.getElementById["adaugareanunt"].submit();
            document.getElementById["adaugareanunt"].action = "mailerPDF.php";

        }
</script>
like image 760
Radish Avatar asked Oct 14 '13 15:10

Radish


People also ask

How do I add two actions to a form?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.

Do forms have to have an action?

Back in HTML4, the answer would be yes. Nowadays with HTML5, you are not required to specify an action attribute. If you have a form tag without an action attribute then the data will be sent to its own page.

Does the submit button go inside the form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML. But visually you can position the submit button anywhere you want with appropriate CSS (float, absolute/relative positioning, etc).


1 Answers

document.getElementById["adaugareanunt"]

change to

document.getElementById("adaugareanunt")
like image 196
babonamu Avatar answered Sep 29 '22 14:09

babonamu