It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Passing text Through a Javascript ( ' is giving error)

Passing text Through a Javascript ( ' is giving error)

Postby notonurnelly on Mon Mar 03, 2008 8:54 pm

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
notonurnelly
 
Posts: 5
Joined: Fri Feb 29, 2008 12:29 pm

Postby dbirley on Wed Mar 05, 2008 9:56 pm

Speaking as a total beginner in JS, nevertheless, I can see the cause of the problem. Look at this:

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

and you'll see that the quote that the code interprets is:

'Large piece piece of Plane I'

because a nod is as good as a blink to a blind horse, and JS says that ' and ' work as a pair.

Now, how to fix this? Candidly it beats me -- I am a VFP programmer, and could fix it easily in that by swapping ' and ". Doesn't work in JS, but I have no doubt some kind person will pop along and solve it for you :shock:
dbirley
 
Posts: 3
Joined: Wed Mar 05, 2008 8:19 pm
Location: Rock Hill, SC


Who is online

Users browsing this forum: No registered users and 1 guest