|
|
Subject:
JAVASCRIPT :conditional cgi script calling on form submit
Category: Computers > Internet Asked by: myq-ga List Price: $10.00 |
Posted:
21 Aug 2005 06:51 PDT
Expires: 20 Sep 2005 06:51 PDT Question ID: 558325 |
Is there a way using javascript (or otherwise) one could have a form such that a different script is called depending on some of the variables used. Just for example, if a person selects 'member' from a dropdown menu,, the form calls perl script 1 and if the person selects 'guest', the form calls php script 2. |
|
Subject:
Re: JAVASCRIPT :conditional cgi script calling on form submit
Answered By: palitoy-ga on 21 Aug 2005 07:28 PDT Rated: |
Hello myq-ga Thank-you for your question. This can be achieved by using the following code. First of all you need the form on your page, it should be something like this: <form name="myform" onSubmit="return submitForm(this.select.value)" action="" method="post" > <select name="select"> <option value="member" selected="selected">Member</option> <option value="guest">Guest</option> </select> <input name="Submit" type="submit" /> </form> Notice, the name of the form and the onSubmit parameter. This calls the submitForm javascript function when the form is submitted. One parameter, the value of the dropdown box, is submitted to the javascript function when the form is submitted. The javascript to redirect you to another script would be done like this and should be placed in the <head> section of your page: <script> function submitForm (choice) { if ( choice == "member" ) { document.myform.action = "member.html" } else { document.myform.action = "guest.html" }; document.myform.submit(); }; </script> Basically, this says if the value submitted (choice - which comes from the dropdown box on the form) is equal to 1 then submit it to "member.html" otherwise it goes to "guest.html". Hopefully you should be able to edit this easily for your own use. If you have any questions on this subject please ask for clarification and I will do my best to respond swiftly. | |
| |
|
myq-ga
rated this answer:
super!thanks! (maybe should take a look at my perl question as well) |
|
Subject:
Re: JAVASCRIPT :conditional cgi script calling on form submit
From: gansos-ga on 30 Aug 2005 16:19 PDT |
I have worked with a similar function before, and there IS a browser specific bug with it, under certain circumstances. In Internet Explorer (IE) for Windows (at least version 6+), if you have an html form tag with the name of 'action', this function tries to set that tag to whatever value the function states, instead of setting the action property of the form object. Obviously, this does not work, and results in weird failure. Here's an example: <form name="myform" onSubmit="return submitForm(this.select.value)" action="" method="post" > <!--This is the offending code for IE--> <input type="hidden" name="action" value="process"> <!--End offending code--> <select name="select"> <option value="member" selected="selected">Member</option> <option value="guest">Guest</option> </select> <input name="Submit" type="submit" /> </form> The function is identical to the one palitoy wrote. As far as I can tell, there is no easy workaround for this. It sounds like you probably won't be dealing with something this specific, but I though you should know, since you asked the question. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |