Jump to content


Photo

innerHTML + XHTML = bug


  • Please log in to reply
9 replies to this topic

#1 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 17 October 2006 - 01:43 PM

I just found out (the hard way) that using innerHTML with XHTML produces a bug.  While whatever one puts into innerHTML will appear on the screen, it won't be placed within the source code.  This is a bit of a problem for me because my script (which is in an external file) relies on CSS (which is in another external file) classes for formatting.  Since the code isn't really inserted into the XHTML, the script doesn't use the classes of the linked CSS file.

I know there are createElement and appendChild methods.  But I need to be able to write within the elements my script creates as well.  Is there a way to do something like a document.write within my body element?  Is write available for an element retrieved with a getElementByID?
Using 'global' is a sign of doing it wrong

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 October 2006 - 04:13 PM

I've never heard of this issue... and if you don't use an XHTML doctype, you're fine?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 17 October 2006 - 04:27 PM

I just tried it without any XHTML references in the head and it's still doing the same thing.  innerHTML should show whatever I have in it in the source, correct?  Because right now it's only showing the empty body element that I used innerHTML to fill.

EDIT: I have a copy of my XHTML at http://www.nightslyr.../calendar2.html
The JavaScript can be found at http://www.nightslyr...dar/calendar.js
The CSS (which isn't working at this point because of my error) is at http://www.nightslyr...ar/calendar.css
Using 'global' is a sign of doing it wrong

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 October 2006 - 10:17 PM

What do you mean by "source code"? Where isn't it appearing?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 17 October 2006 - 10:59 PM

What do you mean by "source code"? Where isn't it appearing?


What I mean is this:
I have a very simple XHTML page that literally only consists of an empty body element (well, there's the normal XHTML Strict head element goodies...).

My script outputs the calendar, which are nested tables, as the innerHTML of the body element.

When I try to view the XHTML source code from the browser, all it shows is my empty body element without any of the innerHTML stuff my script created within it.

Is this normal?  I thought that whatever was placed in innerHTML would be visible in the XHTML source if I looked at the source after the page was rendered.
Using 'global' is a sign of doing it wrong

#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 18 October 2006 - 12:07 AM

I don't think that I have ever seen the replaced html inside of the source code.. Take a look at a chat script that I am working on for a tutorial. http://www.thomashos...atTutorial.html . It is a bit buggy as of yet but you will see that I replace the message textarea with a login text input and button if you are not logged in. However, it never shows in the source. So I do not think that it is a rather serious issue. I have the xhtml doc type declared and I have no problem with the css or anything...

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 18 October 2006 - 12:14 AM

Hmm....

Well, that stinks.  Looks like I'll have to code the tables directly into my markup.
Using 'global' is a sign of doing it wrong

#8 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 18 October 2006 - 12:18 AM

Why do you want the tables to be viewed in the source? I don't think that will really have any baring on what you are doing..

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#9 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 18 October 2006 - 02:52 AM

Well, this is all in relation to the calendar/appointment script I'm trying to make.

Because I've been relying on an external script to print everything (tables and the data inside) using innerHTML, they're not 'seeing' my external CSS file.  I figure that I can code the nested tables (one for the overall structure (3 months across by 4 months high), one for each calendar month) directly into the markup in order to ensure the CSS formatting works as a yearly calendar's overall structure will always remain the same (12 months to a year, at most 5 weeks/rows, depending on how late a month starts, a month).  All that will change are the dates, which are derived by the script.
Using 'global' is a sign of doing it wrong

#10 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:48 PM

That is strange... I've never really tested what happens to CSS attributes written out dynamically...
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users