Date: 05/31/06 (Javascript Community) Keywords: html, database, java So I have this simple function that swaps an image and its caption on an HTML page: function changeBigImg(source, content) { if (source != null) { document.getElementById("showedImage").s document.getElementById("imageCaption").i } } The problem being is that 'content' is being fed from a database, and I have no pull on how they enter the data, and some of the strings being fed into 'content' contain commas, which break the function. If the title of the image has commas or single quotes, then the JS image switching fuction does not work. edited to add examples- This one works: javascript:changeBigImgSideBar('/photo_s sion=1&locale=EN-US&subtype=MIMG','Napoleon Dynamite wishes he had skills like this','height') This one does not: javascript:changeBigImgSideBar('/photo_s sion=1&locale=EN-US&subtype=MIMG','Cindy, Kim, and Q doing their best Sinead O'Connor impersonations','width') Slight variance from js protocol in my examples aren't the problem -- it consistently happens with commas and/or single-quotes. So I was pondering if anyone had a suggestion for a way to replace the commas in the string with commas that will only be read as text, not seperators. Thank you! Source: http://community.livejournal.com/javascript/100742.html
|