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
Related Q & A:
- How do you pause a program until a button is pressed in JAVA?Best solution by Stack Overflow
- How can I debug my php code?Best solution by Stack Overflow
- How To Click A Button In A Popup?Best solution by Stack Overflow
- How to add a button in a Fragment?Best solution by Stack Overflow
- How can I use a button to retrieve a phone 'number' from contacts?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.