View Full Version : innerHTML limitations

10-20-2006, 07:05 PM
Greetings guys, this is my first post on this forum.

I wanted to use Javascript's innerHTML to rotate some questions for an essay i have to do for my college but i found some limitations on the content of innerHTML. It doesn't seem to support <input> attributes such as radio boxes etc.

This is the part of the code with the script;

<script type="text/javascript">
window.onload = ChangeQuestion;

function ChangeQuestion ()
var _main = document.getElementById('main');
var _next = document.getElementById('next');

_next.onclick = function ()
_main.innerHTML = "<pre><em><strong>2. Question text......</em></pre>
Answer 1 .. <input type="checkbox" name="un2" value="nospots"/>
Answer 2... <input type="checkbox" name="un2" value="moreexp"/>
Answer 3.. <input type="checkbox" name="un2" value="morekat"/></pre>";

The script runs fine when i change the content to plain text.

Another thing i wanted to ask is about the quotation, what is the difference of '_' and "_"? Because i noticed a color change on the quoted part of the <inputs> - the "checkbox" part for example - when i used "_" for innerHTML quotation.

PS; If that last question didn't make sence just ignore it. :)

10-20-2006, 07:35 PM
Ok, first of all, it's probably the pre tags that's giving you problems. I wouldn't use them to wrap around input elements. Second of all, in your javascript your string delimiter is " so you need to escape all " inside the string with \

_main.innerHTML = "<pre><em><strong>2. Question text......</em></pre>

Answer 1 .. <input type=\"checkbox\" name=\"un2\" value=\"nospots\"/>
Answer 2... <input type=\"checkbox\" name=\"un2\" value=\"moreexp\"/>
Answer 3.. <input type=\"checkbox\" name=\"un2\" value=\"morekat\"/>";

10-20-2006, 08:39 PM
You are right about them damn pre's. I removed them as well as the blancs between the text and inputs and it's working fine. I guess I'll have to give the desired form by tables. Oh what a headache!

Thanks for the help.

10-20-2006, 09:59 PM
Why not just set up the page layout using CSS as that is what stylesheets are for.

10-20-2006, 10:10 PM
This concerns an essay of mine, for wich i was asked to work with Javascript. Plus I haven't written anyting using css, javascript and php untill last month that i took this essay. I wouldn't know how to do it.
By the way, I'm still a bit lost on how to make a div a link and a submit input. :confused:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum