This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes [Solved] Unexpected behaviour of HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "[Solved] Unexpected behaviour of HTML" Watch "[Solved] Unexpected behaviour of HTML" New topic
Author

[Solved] Unexpected behaviour of HTML

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
I have developed one JSP page having HTML and JavaScript in it. Here is the excerpt of page.

Here when I click on submit button, it submit the first form and executes logout.htm. But when I changed that first form to,

It has started working correctly.
What could be the possible reason for this?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It is invalid markup to have a form nested in another. Read the HTML Spec.

Eric
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Eric,
there is no nested form. Please look at the code carefully.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well I am going by what you posted and you are not showing all of the mark-up / closing tags so I am going off of what people have done in the past in forums.

Looking at your code in your post, your markup looks bad, you can not have the form tag around table cell like that. It would have be entirely in the cell or around the whole table.

And when it fails do you get any JavaScript errors?

Eric



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61312
    
  66

Yes, look at the HTML code carefully. Your first example is invalid!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Eric Pascarello wrote:Looking at your code in your post, your markup looks bad, you can not have the form tag around table cell like that. It would have be entirely in the cell or around the whole table.

I use table for alignment of elements (I don't know div tag properly).So very first tag after body tag is table tag and I adjust all the elements in it. So it is obvious that form tag might come under some td tag and the same td tag may contain another table. In my case it's like this ,
Second Form


Excerpt of Header.jsp


So at the run time everything will be merged in single page. And everything looks fine.

Isn't this the proper way of alignment of elements? Please guide me if I am wrong. Please justify your statment.

Eric Pascarello wrote:And when it fails do you get any JavaScript errors?

Except the line in header.jsp, I didn't use javascript atall in this page. Actually, I don't get any error atall but it behaves unexpectedly. When I submit the button(I'm done) then it should submit the second form and hence it should call the controller associated to that pattern. But in my case it submit the first form and call the logout controller.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Bear Bibeault wrote:Yes, look at the HTML code carefully. Your first example is invalid!

Bear, Form tag is closed properly and there no nesting of forms. What is invalid in that?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The HTML <form> element doesn´t allow a shorttag. Use <form></form> instead of <form />.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hey Bauke,
How did you come to know about this fact? I have also learned HTML.

And bear, I guess you were pointing the same thing, right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61312
    
  66

HTML != XML
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Bear Bibeault wrote:HTML != XML


I didn't understand your gesture. Do you mean this kinda stuff is feasible in XML but not in HTML. Please be clear and simple.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61312
    
  66

Clear and simple: HTML is not XML, do not expect it to act like it. Self-closing tags are a no-no.

Now XHTML is a different matter...
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Thanks Bear,Bauke and Eric!
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Vishal Pandya wrote:Hey Bauke,
How did you come to know about this fact? I have also learned HTML.

Learn the (X)HTML DTD out of head.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Solved] Unexpected behaviour of HTML