Apostophe (') causes an error. Why?

Hello again Experts

I have a problem that I can't figure out for the life of me.

I have put the code here for you to play around. The problem is, if I use an apostrophe within the data array I get an error. It happens even if I use an escape (\'), decimal (') or as itself (') and I can't figure out why.

Here's the code on the first page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<title>Property Details</title>

<script language="JavaScript">
// Create a Table from a JavaScript Array script by lil_Puffball at http://www.experts-exchange.com //
// loadDetails() script by ren_b at http://www.experts-exchange.com  modified for use here by me.//
// Put together by lil_Puffball and me//

var data=new Array();

data[0] = " | 914 NW 82nd Street, Bradenton | $298,000 | 4 | 2 | 1,960 | This is a 4 bedroom 2 bath pine meadow home overlooking a beautiful lake. All the sliding doors are pocket doors that open into a beautiful pool area that has just been re screened. Many updates including: jacuzzi tub, laminated wood floors, vaulted ceilings, attic fan, new trane heat pump, newer water heater, second bath opens into pool area, underground sprinkler system feed from lake (new pump). | "

data[1] = " | 8843 Etera Drive, Sarasota | $227,000 | 3 | 2 | 1,671 | Incredible floor plan, with two major upgrades 1) Extended family room / den adding an extra 140sqft 2) Living room wall unit, that looks beautiful with the textured vaulted ceiling. The Village Walk community has it all… Town Center, entire lawn maintenance, 2 heated pools, tennis courts, security, fitness center, shops, salon, bank, post office, café and deli, wide paths, lakes, bridges. Everything you need for the ultimate Florida lifestyle. | "

data[2] = " | 1125 North Bay East Street, Tampa | $111,900 | 4 | 2 | 1,576 | Needing A little TLC this 4/2 1576 sqft home makes the perfect investment. Subject has appraised in the 130s so consider having your closing costs included into the price. Big laundry area and large living room. Air con is only 3 yrs old. Large shed outside. Bring your buyers and bring your investor. | "

for(i=0;i<data.length;i++){data[i]=data[i].split("| ");}

for(i=0;i<data.length;i++){data[i][0]=" ";}

for(i=0;i<data.length;i++){data[i][1]="<b>"+data[i][1]+"</b>";}

for(i=0;i<data.length;i++){data[i][2]="Price: "+data[i][2]+"";}
for(i=0;i<data.length;i++){data[i][3]="Bedrooms: "+data[i][3]+"";}
for(i=0;i<data.length;i++){data[i][4]="Bathrooms: "+data[i][4]+"";}
for(i=0;i<data.length;i++){data[i][5]="Total Area: "+data[i][5]+" square feet";}
//for(i=0;i<data.length;i++){data[i][6]=" ";}
for(i=0;i<data.length;i++){data[i][7]="<a href='#' onclick=\"loadDetails('"+data[i][1]+"','"+data[i][6]+"')\" style='color:red'>... more</a><hr>";}

function loadDetails(HoName, HoDetails) {
  document.location.href = "viewer.htm?"+escape(HoName)+"&"+escape(HoDetails);
}

function createTable(){
  var numcols=1;
  var numrows=data[0].length,trow,tcell;
  var tbl=document.getElementById("container").firstChild;
  for(n=0;n<data.length;n+=numcols){
    for(i=0;i<numrows;i++){
      trow=document.createElement("tr");
      for(j=0;j<numcols;j++){
        tcell=document.createElement("td");
        if(!data[n+j]){tcell.innerHTML="";}
        else{tcell.innerHTML=data[n+j][i];}
        trow.appendChild(tcell);
      }
      tbl.appendChild(trow);
    }
  }
}


</script>

</head>

<body onload="createTable()">

<table id="container" align="center" cellspacing="0" cellpadding="0" border="0" width="400"><tbody></tbody></table>

</body>
</html>

And here is the code for the second page called 'viewer.htm'

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Details Viewer</title>

<script language="JavaScript" type="text/javascript">
// read_pants() Script by ren_b at http://www.experts-exchange.com. Used with loadDetails() script.  //
// All the other nonsense by me //

var pants = new Array();
function read_pants() {
      pants = document.location.toString().split('?')[1].split('&');
      for(i in pants)
      pants[i] = unescape(pants[i]);

      document.write(pants[0]);
      document.write("<p>");
      document.write(pants[1]);
}

</script>

</head>

<body>

<script>read_pants();</script>

</body>
</html>

I know all the coding works as I have used it successfully before, however, I didn't need to use an apostrophe.

Hope you can help.

Regards

Pantyboy
LVL 1
Martin CotterillDabblerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
Change your function read_pants()  to this:

var pants = new Array();
function read_pants() {
     if(document.location.search){
       pants = document.location.search.split('?')[1].split('&');
       for(i in pants)
         pants[i] = unescape(pants[i]);

     }
       document.write(pants[0]);
       document.write("<p>");
       document.write(pants[1]);
}

0
GwynforWebCommented:
a fails afe way of solving the ' problem is this, for:-  Micheal's book

data="Micheal"+"'"+"s book"
0
Martin CotterillDabblerAuthor Commented:
Hi both

Many thanks for the replies. However, firstly, Zvonko, my apologies, I should have specified that the error appears on the first page. If you leave omit apostophes within the data[#]... array the second page loads without any problems. The error comes on the first page when an apostrophe is used in the text of the data[#] array. for example. In data[2] = "..." the line ...appraised in the 130s... should really read ...appraised in the 130's... The apostrophe between 130 and s creates the error. I hope that helps. Incidently, you can't use escaped quotation marks (\") either.

Secondly, GwynforWeb, I want to keep the writing of the data as simple as possible, as the person who will be updating it has very little knowledge. My intention is to put the data into an external file once it's all working. Also it doesn't work in this case.

Sorry both.

Kind regards

Pantyboy
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Martin CotterillDabblerAuthor Commented:
Hello again

Something else I forgot to mention (slapped wrists all round). The apostrophe only affects the data[#] statement it appears in.

ie: If an apostrophe appears in statement data[2] it will only affect that statement. The statements, data[0] and data[1], will send their data to viewer.htm correctly, provided they do not contain apostrophes.

I don't know if that narrows down the problem.

Regards

Pantyboy
0
Martin CotterillDabblerAuthor Commented:
Hello again

I've found a way round my apostrophe situation. Because I couldn't use ', \', or #39; I was stumped if an apostrophe was required.

Under 'Additional named entities for HTML' at http://www.w3.org/TR/WD-entities-961125, 'Appendix C: Character Entities for special symbols and BIDI text' shows a character which works.

It is the 'right single quotation mark' which is called by using '&rsquo;' or '&#8217;'.

A big thank you goes out to Zvonko and GwynforWeb for trying to resolve the problem. I have now 'aquired' another situation which I need help with and I will post once I get it straight in my head the best way to ask the question.

Regards

Pantyboy
0
PashaModCommented:
Closed, 250 points refunded.
PashaMod
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.