atrum Posted June 17, 2008 Share Posted June 17, 2008 Hello all, I have been trying to figure out how to accomplish using java to write html to a specific section in the body of my page. I want to use a function to call html and text, and place it in a specific area of the page. So I have my function <script type="text/javascript"> function test() { document.write("html to be inserted"); } </script> Now How do I get the onclick event to write to let's say to a table data tag in the body? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 the easiest way is to give the table tag an ID: <td id="write2me"></td> then... <script type="text/javascript"> function test() { document.getElementById('write2me').innerHTML = "html to be inserted"; } </script> also...just me being picky...but JAVA is not the same as JavaScript Quote Link to comment Share on other sites More sharing options...
atrum Posted June 17, 2008 Author Share Posted June 17, 2008 Thank you for the assistance. Just one more question. What if instead of targeting a td tag. could I target a <p> tag. Also let me just explain what I am trying to do. On my page, I have a menu with links to a seprate page. Each page is identical in terms of layout and style. The only difference is the contents of the body. My goal is to keep the contents for all the pages in a seprate file all together, and only have 1 acutall html page. The menu will actually contact javascript functions, that when pressed, replace the contents of the body, with the corrisponding content for that link. Am I crazy or is this a practical solution? Quote Link to comment Share on other sites More sharing options...
ober Posted June 17, 2008 Share Posted June 17, 2008 That's actually not a practical or sustainable architecture. Good luck scaling something like that. And what if someone has JavaScript disabled? You're completely screwed in that case. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 Yeah, don't really on JavaScript being enabled for your page to work. Also, JavaScript is not SEO friendly. So search engines won't be able to parse and index the contents of your pages if you load them that way. On a side note, you can give any HTML element an ID, and access it with document.getElementById('the_id_here'). The innerHTML attribute will only work on elements that can have contents (so won't work on stuff like BR, HR, etc) Quote Link to comment Share on other sites More sharing options...
atrum Posted June 17, 2008 Author Share Posted June 17, 2008 Hmm, well after reading my post over, you are right. I think I will explore other avenues. What I really need is a content management system. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 i personally am a fan of CMSMadeSimple Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted June 17, 2008 Share Posted June 17, 2008 This is possible using PHP. My advice would be to store vairables for each page (all the content in seperate variables) and then have if statements. If you need help doing this feel free to PM me. Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 I know it's already been said, but java != javascript. They are two different programming languages that do very different things, which means it can be confusing if you use the name of one when meaning the other. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.