Connecting Tech Pros Worldwide Help | Site Map

Javascript onSubmit

  #1  
Old November 18th, 2008, 01:45 AM
trpost@gmail.com
Guest
 
Posts: n/a
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.
  #2  
Old November 18th, 2008, 02:05 AM
Conrad Lender
Guest
 
Posts: n/a

re: Javascript onSubmit


On 2008-11-18 02:39, trpost@gmail.com wrote:
Quote:
<form name=form1 onSubmit=tst();>
....
Quote:
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.
This was just answered here yesterday... Please try to at least read the
subjects of the most recent threads.

You need to:
1) run your HTML through a validator before you start debugging scripts
2) use onsubmit="return tst()"


- Conrad
  #3  
Old November 18th, 2008, 02:05 AM
RobG
Guest
 
Posts: n/a

re: Javascript onSubmit


On Nov 18, 11:39*am, trp...@gmail.com wrote:
Quote:
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.

Quote:
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. :-)


--
Rob
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript - Onsubmit problem in Firefox bubs81 answers 2 June 28th, 2009 10:51 PM
Javascript onsubmit() doesn't fire WTF? GilBates answers 2 May 25th, 2007 12:02 PM
Updating a texbox with Javascript Denise answers 3 November 19th, 2005 06:29 AM
Javascript OnSubmit/JSP Liquidchild answers 3 November 4th, 2005 01:46 AM