Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    innerHTML limitations

    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;
    Code:
    <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>
    <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>";
        }
    }
    </script>
    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.

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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 \

    Code:
    _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\"/>";

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,607
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Why not just set up the page layout using CSS as that is what stylesheets are for.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New to the CF scene
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •