Aditya H.
Aditya H.

Reputation: 1

javascript and jsp

I have a problem with my jsp file... inside it I have a form and in that form I have an onsubmit method that is basically calling a javascript... the problem is that whenever I click on a button it always redirects me to the page, whether it's true or false

Upvotes: 0

Views: 164

Answers (4)

Aryan
Aryan

Reputation: 1877

I guess, you are using "Submit" button and thus form gets submitted anyway. Use a normal button set onclick event for that and write form submitting code in java script function.

May this help.

Upvotes: 0

BalusC
BalusC

Reputation: 1108537

You likely have something like:

<form onsubmit="someFunction()">

instead of

<form onsubmit="return someFunction()">

Fix it accordingly.

Upvotes: 1

am9u
am9u

Reputation: 119

what cherouvim said.

also, in the case that the onsubmit handler already should be returning false, if there's any javascript error in the handler, then the return statement may never get evaluated and the form will submit.

Upvotes: 1

cherouvim
cherouvim

Reputation: 31903

You probably need to return false after the javascript processing which is bound on the button click.

Upvotes: 1

Related Questions