• Post Reply Bookmark Topic Watch Topic
  • New Topic

Executing a method ONLY on submit  RSS feed

 
B Wiley Snyder
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
How would you go about executing a method when the submit button is pressed(not before) in a post form without using javascript? Or do you have to use javascript onClick?

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you go about executing a method


What kind of method? A Javascript method? If so, what do mean by "how can I execute a Javascript method with Javascript"?

If it's a JSP/Java method, you can't.

Or, perhaps it's the form tag's onsubmit handler you are after?
 
B Wiley Snyder
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


What kind of method? A Javascript method? If so, what do mean by "how can I execute a Javascript method with Javascript"?

If it's a JSP/Java method, you can't.

Or, perhaps it's the form tag's onsubmit handler you are after?


hello,
I'm trying to send a timestamp to a credit card gateway with the transaction details. They tell me I have to generate this timestamp when the submit button is pressed to the gateway. The timestamp is generated and inserted into a hash inside a method.

Basically I need this method executed at the time the submit button is pressed. I have seen javascript examples of this being done but I wanted to use something other then javascript. I thought there was something else.

I hope that makes better sense,
thanks

 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a input type "hidden" in the form and in the "onSubmit" event, set the value of the hidden type to the current date. The current date can be obtained in javascript by "new Date()".
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AFAIK

If the timestamp has to be the exact instant the submit button is pressed, JavaScript is the only way. But in general, you should not rely on JavaScript for any critical data, a malicious user can easily hack it to do something you did not intend.

A better option might be that the data entered by user is sent to a Servlet under your control, where you create the Timestamp, and then forward that data to the gateway.
 
B Wiley Snyder
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sonny Gill:
AFAIK

If the timestamp has to be the exact instant the submit button is pressed, JavaScript is the only way. But in general, you should not rely on JavaScript for any critical data, a malicious user can easily hack it to do something you did not intend.

A better option might be that the data entered by user is sent to a Servlet under your control, where you create the Timestamp, and then forward that data to the gateway.


Thats exactly what I am doing and thats also why I didnt want to use javascript but if I can call the onsumbit to execute my method that creates the stamp I'm set.

thanks for all the replys

 
B Wiley Snyder
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A better option might be that the data entered by user is sent to a Servlet under your control, where you create the Timestamp, and then forward that data to the gateway.]


wait a second now i see what you are saying. I really don't want to use javascript and I'm finding out onClick and onSubmit are both javascript so I will forward the post to a new servelt that creates the timestamp and forwards the post variables. I hope thats do-able it just seems like an awfull lot to go through. And I thought it would be a simple task to send the transaction to a credit card gateway . Would you happend to know how I would go about doing that.
So I just make a new doPost servlet in the code I just do something like "onload" response.forward("The URL")?

thanks alot !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!