• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Creating table in a "div" HTML element

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic