Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional onsubmit based on form data

Status
Not open for further replies.

N8bak

Technical User
Aug 16, 2004
25
US
Greetings. We are migrating our sites from an existing C based CGI script to a more functional Perl based app. During the transition we need to be able to route the user/customer to one script or the other based on the phone number they input. I'd like to set up some sort of conditional statment within the new perl script for the submit button.

If phone# = xyz
then
submit to old CGI script
else
continue with perl CGI

I've been told that this can be handled via the onsubmit event. Any ideas?


~N8

"Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon `em." - Twelfth Night, II:5
 
In Javascript, you can call a validate function in the onSubmit event. If the function returns false, the form won't be submitted.

Cheers,
Dian
 
Thanks for the reply Diancecht. The form needs to submit two different ways depending on the phone#.

If phone# = xyz
then
submit to old CGI script
else
parse form data with perl CGI

~N8

"Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon `em." - Twelfth Night, II:5
 
Ummm.... you posted the same pseudo code in both posts. Can you post your actual code that isn't working? You will need to change the action parameter of the form tag in the onsubmit handler function.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
<td><input type="SUBMIT" value="Refill"/>
<td><input type="RESET" value="Clear"/>

~N8

"Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon `em." - Twelfth Night, II:5
 
Seriously? That's the code?

.
.
.
.

Where's the javascript?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
The existing CGI script does not contain any javascript. I have to set up some sort of conditional to handle two different form parsers and was told that javascript could accomplish this using the onsubmit option.

~N8

"Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon `em." - Twelfth Night, II:5
 
and was told that javascript could accomplish this using the onsubmit option.

You were told correctly. What part of the validation script are you having problems with?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
All I need to know how to switch between using the current script to parse a form versus routing to an external cgi script. This needs to be done when the user clicks on the submit button. You'll have to forgive me but my prior experience with javascript is very minimal. While I can construct a simple if/then/else statement, I don't know the finer points of the onsubmit function.

~N8

"Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon `em." - Twelfth Night, II:5
 
While I can construct a simple if/then/else statement, I don't know the finer points of the onsubmit function.

Fortunately for your script, that's about all you need to know. Now, as far as using javascript to validate your form, there's not a lot to know. I gave you the answer above - you need to change the action parameter on your form (so that it submits to the proper file). As diancecht said above, you have to use the onsubmit handler on the form. So, what you need to do is spend a little time doing some research on using javascript to submit a form (which is a simple concept, so if you know anything about programming - which you should if you're on this site - then you will not have a problem getting it to work) Take a look over this site ( to get a little tutorial (by the way, it was the first hit in google when searching for "javascript onsubmit validation", you did search google first, right?). After reading that tutorial you should be able to get a good start on your validation script.

After you've started writing the validation script, if you still run into problems come back and post what work you have done and we will help you fix your problems.

Tek-tips is not a "get all your code written for you" website. Make an honest attempt to do it yourself (as it was pretty obvious that you hadn't when you started posting pseudocode) and when you run into a problem come back and we'll be glad to help.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top