how to make a form that won't submit

A

Andy Fish

Hi,

I have a web page with some form controls on it. When the user presses the
'OK' button, some javascript talks to another page in another window. This
form is never destined for the server so I don't want it to have any concept
of "submit".

However, I have noticed that pressing enter in a text field will submit the
form to the server. Because I haven't specified a form action, it just tries
to post to the root URL for my site which obviously doesn't work.

Currently I'm doing the processing in the onclick event of the button
because I've heard that <form action="javascript:..."> is not portable. Is
there any way to specify that a form is not submittable? I don't really want
to have keypress handlers on every text field because I'm sure there is a
proper way to achieve this.

Andy
 
A

Andy Fish

Thanks, the
onsubmit="return false;"
is exactly what I was looking for.

the reason I had a form was that it seemed to be the best way to refer to
the controls within javascript i.e.
document.myForm.myTextBox

Andy



Jim Dabell said:
Andy said:
I have a web page with some form controls on it. When the user presses the
'OK' button, some javascript talks to another page in another window. This
form is never destined for the server so I don't want it to have any
concept of "submit".
[snip]

It sounds like you don't want a <form> element at all. Unless you need to
support a browser that can't handle <input> elements outside forms
Is there any way to specify that a form is not submittable?
[snip]

<form onsubmit="return false;" ...>
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top