Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Creating table in a "div" HTML element

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Javaranchers,

There is an <div> element(Its id is previousorders) in my html page.
Through javascript, I would like to insert a table in this <div> section.
but when I use the innerHTML property it behaves in an unusual way.



It creates a table but just includes the first row in table and ends the table
if we view the HTML source it looks like this

<table width='100%'><tr><td colspan='2'><h3>Previous Orders</h3></td></tr></table>



Although I have appended an </table> tag at the end.

Could anyone please provide their input on this ?

Thanks,
Hardik Raja
SCJP 5.0

[ August 20, 2008: Message edited by: Hardik Raja ]
[ August 20, 2008: Message edited by: Hardik Raja ]
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you construct the complete html using a variable and then finally set to innertHtml? Then you can even alert out the generated html to make sure it is what you expected?

Two cents.
 
Marshal
Posts: 67414
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. Anything you insert using innerHTMlL should be valid -- not invalid bits and pieces.

If you want to build the table piece-meal, explore using the DOM API to create the elements.
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Santhosh Kumar & Bear Bibeault,

Thanks for your responses. It has helped me to understand the notion of innerHTML and thus solved my problem.

Regards,
Hardik
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic