|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
My .innerHTML for one part of my program is not working!
Please explain this problem to me if you can??
1 var str = 'The Raven G&CC'; 2 idname = 'SPcodename' + q;"); 3 alert(str+' !');"); 4 document.getElementById('idname').innerHTML = str; 5 alert(document.getElementById('idname').innerHTML + ' !'); As you can see a very simple javascript code snippet. This program use to work but not anymore. The problem is that when the first alert is shown I get the proper string showing in the box 'The Raven G&CC !', but in line 4 when the str variable gets set to the id 'idname' tag.innerHTML the content of the string gets severed right after the 'G' and the only part of the string to get displayed is 'The Raven G'. When I alert it in line 5 I get the same result 'The Raven G !'. This program use to work and I did not get this problem. I tried changing the & to another variable and it worked ie ('The Raven GVCC !'), but it should work for all string characters and I need the &. Also I have other coded areas in my program where I set a string to an .innerHTML tag with an ampersand(&) and it works fine. It is just for this group of HTML tags for some reason. It is like somebody has put a resident program in my program which is not in my view to see or decipher. I thought that somebody might have a program which, unbenounced to me, saves another copy similar but with some additions to my program when I compile it but when I view the source code it is the same as my original code. Anyway, if you can tell me how I can get the 'The Raven G&CC' string to display in the above .innerHTML tag. I will deem you a genious! Thanks for the interest in my problem and possible solution. Derek |
|
#2
|
|||
|
|||
|
"); <-- This at the end of lines 2 & 3 should not be there unless you did not post the full code. Every closing brace needs an opening brace, same with quotes.
Also remove the quotes from around your variable idname where it is used to get element by id. document.getElementById('idname') is looking for an element with the id='idname' literally, change to document.getElementById(idname). Try this: (although make sure that you have an element with id that equals 'SPcodename' + q, can't tell what q equals from the code you supplied) Code:
var str = 'The Raven G&CC'; idname = 'SPcodename' + q; alert(str+' !'); document.getElementById(idname).innerHTML = str; var i = document.getElementById(idname).innerHTML.replace(/&/g,"&") alert(i + ' !'); Last edited by HazardTW; 06-24-2007 at 05:09 PM. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|