Page 1 of 1

Javascript Error in PHP ' in text

Posted: Mon Mar 03, 2008 4:47 pm
by NotOnUrNelly
~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi All, 

I have developed a simple image library that swaps images and text whenever a thumbnail is clicked. 

http://www.runthelakes.co.uk/wain/show_ ... mmitNo=150 

The above page has 4 images, each with its own comments all drawn from a mysql database using php. 

The fourth image will not click, this is due to the text in the database reading 

Large piece piece of Plane I'm guessing a Wing Strut 

This is the reason the text and image will not change. 

If I change this text in the database to 

Large piece piece of Plane Im guessing a Wing Strut 

That is without the ' in I'm 

The images will swap. 

Here is the a list of the code causing the problem

Code: Select all

 
 
<img src="/wain/images/fells/uploads/Interest/th_377.jpg" border=0 onclick="MM_setTextOfLayer('TextLayerA','','Large piece piece of Plane I'm guessing a Wing Strut');MM_swapImage('walk','','/wain/images/fells/uploads/Interest/di_377.jpg',1)" > 
 
 
Here are the Java routines

Code: Select all

 
 
function MM_swapImage() { //v3.0 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) 
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} 
} 
 
function MM_setTextOfLayer(objName,x,newText) { //v4.01 
  if ((obj=MM_findObj(objName))!=null) with (obj) 
    if (document.layers) {document.write(unescape(newText)); document.close();} 
    else innerHTML = unescape(newText); 
} 
 
 
How can I get round this problem is there anything I can do when calling the code or should grammar such as ' be avoided. When submitted to adatabase.

Many Thanks in Adavnace
Jamie


~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Javascript Error in PHP ' in text

Posted: Mon Mar 03, 2008 7:40 pm
by Chris Corbyn
addslashes() :)

PS: Your page takes a long time to load since the images are rather large (for example header JPEG is over 54KB). Not sure if you've optimized them in any way for the web but I'd suggest making those images as small as possible.

Re: Javascript Error in PHP ' in text

Posted: Tue Mar 04, 2008 10:34 am
by pickle
Java != Javascript