aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes cr in text submits the form... sometimes? [ie] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "cr in text submits the form... sometimes? [ie]" Watch "cr in text submits the form... sometimes? [ie]" New topic
Author

cr in text submits the form... sometimes? [ie]

Matt Horton
Ranch Hand

Joined: Feb 06, 2002
Posts: 107
Hello...
I'm trying to determine the root of the following behavior, I have been unable to determine which sequence of html is the cause.
On some of my pages, hitting return in a textbox actually fires submit. On other pages, this is not the case. I'd prefer the latter case... is there some set logic that evokes this behavior? Some set of tags that are responsible?
Thanks in advance...
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Matt,
Right now, your form probably looks something like this:

or this:

If you extract the submit functionality and the action attribute into a little JavaScript, your form should stop doing that, e.g.:


hth,
g.
Matt Horton
Ranch Hand

Joined: Feb 06, 2002
Posts: 107
Thanks for your time Garann.
The design of my pages actually follow the logic of your first example... in that none of my buttons are submit buttons... instead they execute logic that later calls something, e.g.

The way in which I have subdued this behavior is to add the following logic in my form tag...

I was curious about the behavior initially... that is, would the validation there suppress my javascript .submit() logic. So far, it appears that everything is fine.
Do you know of downstream issues I will run into? Is the intent of the onsubmit() logic merely to validate against the submit button... as well as the quirky submit I am encountering upon hitting carriage return in textboxes?
Thanks again...
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Matt,
Should have done a little more research before I replied. I encountered the same behavior when I did a few tests - no matter how little input the FORM had about what to do when it was submitted, it went ahead and submitted anyway.
In answer to your question, the workaround you're using seems like a good idea to me. The onSubmit handler, I believe, is there to catch a submit event in the FORM - hitting enter or clicking an INPUT of type SUBMIT. In your JavaScript function, you're calling a method of form, but I would think that because you're not inside the form, the onSubmit handler isn't going to care. Either that or it won't have a chance, being that control will have already been passed to the next page/Servlet named in the action attribute.
Perhaps someone with a deeper understanding of events can comment?
g.
Matt Horton
Ranch Hand

Joined: Feb 06, 2002
Posts: 107
Thanks again for your time Garann, I think you've nailed the rationalization (ie the js is outside of the form, so it should be transparent).
Those little inputs are buggers (though I've resolved the issue I'll have to achieve greater understanding at a later date by figuring out why those few inputs do not sumbit() upon return) .
[ September 27, 2002: Message edited by: matt horton ]
 
I agree. Here's the link: jrebel
 
subject: cr in text submits the form... sometimes? [ie]
 
Similar Threads
Printing problem
contains() & equals()!
Ajax and PDF data via Javascript
scenarios for custom tags
RequestDispatcher forwarding