Can someone please tell me what is wrong with the javascript below. function imageDescSwap(imageDesc, jobid) { document.getElementById('imageDescArea+jobid+').innerHTML = imageDesc ; } Here's the error message that occurs when this is run: document.getElementById("imageDescArea+jobid+") has no properties Obviously, the jobid is not being interpreted as a variable as I want it too, but as a string instead.
try this: document.getElementById(eval('imageDescArea'+jobid)).innerHTML = imageDesc; } or : idStr = 'imageDescArea' + jobid ; var obj = document.getElementById(idStr); if (obj != null) obj.innerHTML = imageDesc ; notes 1. Make sure to check for null value before using the return value of getElementById (or any function like it) 2. If your code has many many "document.getElementById()" consider replacing it with a shorter function name like : function GID(id) { return document.getElementById(id); } this will make your page size smaller.