Javascript Error in PHP ' in text

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Javascript Error in PHP ' in text

Post 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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Javascript Error in PHP ' in text

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Javascript Error in PHP ' in text

Post by pickle »

Java != Javascript
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply