Javascript onSubmit

T

trpost

I am trying to utilize a form to display a message and not submit when
the submit button is clicked, here is an example on what I have done:

<script type="text/javascript">
<!--
function tst()
{
alert('hi');
return false;
}
-->
</script>

<form name=form1 onSubmit=tst();>
.....
....
</form>

When I submit the form, I get the alert message and then the page
refreshes, what I would like is to submit and see the message and then
be returned to the form without having it submit.
 
R

RobG

I am trying to utilize a form to display a message and not submit when
the submit button is clicked, here is an example on what I have done:

<script type="text/javascript">
<!--

Get rid of the HTML comment demlimiters, they do nothing useful.

function tst()
{
        alert('hi');
        return false;}

-->
</script>

<form name=form1 onSubmit=tst();>

Remember that in-line listeners are bundled into a function and called
by the handler, they must return false to cancel submit, so:

<form ... onsubmit="return tst();">


And don't forget to put quotes around attribute vaules. They aren't
always necessary, but it's a good habit and it is needed here. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top