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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts

    document.getElementByID and innerHTML

    Hello! First timer on this forum! I just started a webdevelopment course, and I have just encountered a little problem. I am fairly new to this stuff, so bear with me

    I wrote a function for a so-called "crumbs path". When you click on a certain <div> in the menu, it calls the function, which changes the innerHTML of a <span> somewhere on the page. So far, so good: it works perfectly in Netscape and Opera. Then I try it in IE 6. The code works, and it does exactly what it is supposed to do, but yet it gives me a syntax error. The innerHTML is changed to a pretty complicated contamination of strings, but I am pretty sure there is nothing wrong with that. Does anyone have an idea?

    Here is the function:
    Code:
    function SwitchKruimel(text, submenu) {
      if(document.getElementById) {
        document.getElementById('kruimelpad').innerHTML = 
    	'&nbsp;You are here: <a href="index.html">home</a>' +
    	' :: <a href="#" onClick="SwitchMenu(' + 
    	'"' + submenu + 
    	'");SwitchKruimel("' + 
    	text + 
    	'","' + 
    	submenu + 
    	'")">' + 
    	text + 
    	'</a>';
      }
    }
    Here is the <span> which changes (in other words, the crumbs path):
    Code:
      <span id="kruimelpad">
          &nbsp;You are here: 
         <a href="index.html">home</a>
      </span>
    And here is the function called:
    Code:
    <div class="menutitle" onClick="SwitchMenu('sub1');SwitchKruimel('my websites','sub1')"> 
      - my websites - 
    </div>
    The HTML of the crumbs path looks like this: You are here: home and it changes into You are here: home :: my websites, just as it is supposed to - but unfortunately with that nasty yellow triangle in the bottom left corner in IE. SwitchMenu() works and doesn't give me any problems, I have located the error to be in SwitchKruimel() - but that's about it. I can't find it, and some help is much appreciated!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Oddly enough, turns out 'SwitchKruimel' is a reserved word in JavaScript. You'll have to re-name that function.

    Only kidding. You've got some embedded double quotes in that string, conflicting with the doubles bounding the HTML string. Use escaped singles (as you'd use unescaped ones if this were HTML)...

    Code:
    ' :: <a href="#" onClick="SwitchMenu(' + 
    	'\'' + submenu + 
    	'\');SwitchKruimel(\'' + 
    	text + 
    	'\',\'' + 
    	submenu + 
    	'\')">' +
    I'd clean up that entire fractured string, which is an error waiting to happen...

  • #3
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts
    Quote Originally Posted by adios
    Oddly enough, turns out 'SwitchKruimel' is a reserved word in JavaScript. You'll have to re-name that function.

    Only kidding.
    I know, I have a pretty nifty language. Thank you sir!
    You've got some embedded double quotes in that string, conflicting with the doubles bounding the HTML string. Use escaped singles (as you'd use unescaped ones if this were HTML)...

    Code:
    ' :: <a href="#" onClick="SwitchMenu(' + 
    	'\'' + submenu + 
    	'\');SwitchKruimel(\'' + 
    	text + 
    	'\',\'' + 
    	submenu + 
    	'\')">' +
    I'd clean up that entire fractured string, which is an error waiting to happen...
    Yeah, it works like a charm now. I suspected it was the whole string which rendered the error, but up to now I am a champion in the "write-code-as-longwinded-as-possible"-category. Anyway, I'm glad enough that it works now. Thanks!


  •  

    Posting Permissions

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