What is an easy code for a form in PHP?

Javascript or PHP code to alter the form action depending on a button

  • I am working on a form that can be viewed at: http://www.nrcpara.org/bookstore/testing/orderform.php I need to be able to alter the action of the form depending on whether the user selects to to pay by Credit Card (type=payment name=card) or Money Order (type=payment name=check). For example, if the Credit Card option is selected, it will go to one URL, but if the Money order button is selected it will go to another. Thanks, Christopher

  • Answer:

    Hi Christopher, A simple piece of javascript will solve your problem... Add the code below to your page. It will work with both IE and Netscape. Add the this onclick event to your payment radio buttons: onclick="changePaymentType()" <input type="radio" name="payment" onclick="changePaymentType()" value="card" checked> <input type="radio" name="payment" onclick="changePaymentType()" value="check"> Put this script block somewhere on your page (you'll need to replace the url's with the correct one's): <script language="javascript"> function changePaymentType(){ var myForm = document.forms.form1 if (myForm.payment[0].checked){ myForm.action = 'myUrl1.php' }else{ myForm.action = 'myUrl2.php' } } </script> Good luck! Daaf

toph-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.