Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Apostrophes in data 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I hope this is the correct forum; I couldn't decide between this and ColdFusion. Sorry if I'm wrong on this.

I'm working on a pick list that will populate a text input when clicked. The onclick value results in error because some data rows have an apostrophe in the data.

I'm at a loss as how to proceed from here... Any help appreciated.

Note: A quote could occur as well.

Server Side (Cold Fusion):
Code:
<div id="StallionList#i#" style="display: none;" onclick="document.getElementById('StallionList#i#').style.display='none';">
 <ul id="ulStallionList#i#" class="suggestList">
  <cfloop query="getSireList">
   <li value="#getSireList.OBNO#" onclick="document.getElementById('StallionName#i#').value='#getSireList.Name#';">
    #getSireList.Name#
   </li>
  </cfloop>
 </ul>
</div>

Results in this html (the row where value=8296 fails):
Code:
<li value="28542" onclick="document.getElementById('StallionName1').value='ALARMER';">
 ALARMER
</li>
<li value="8296" onclick="document.getElementById('StallionName1').value='ALBIE'S TRUCK STOP';">
 ALBIE'S TRUCK STOP
</li>
<li value="38418" onclick="document.getElementById('StallionName1').value='ALBIES TRUCKER';">
 ALBIES TRUCKER
</li>


Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
If you content has apostrophe's then either you can't surround it with single quotes, or you'll need to escape the apostrophe. Same applies with the quotes.

To escape a quote or apostrophe it needs to be preceeded by a / forward slash character. Since your values come from Coldfusion variables, you'll need to use that to escape them.

There must be some CF function that will parse the string, and replace any apostrophe's with an escaped version.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Sorry this was the wrong forum.
Thanks for the clue. I couldn't see the forrest for the trees...

server side solution:
Code:
<div id="StallionList#i#" style="display: none;" onclick="document.getElementById('StallionList#i#').style.display='none';">
 <ul id="ulStallionList#i#" class="suggestList">
  <cfloop query="getSireList">
   <li value="#getSireList.OBNO#" onclick="document.getElementById('StallionName#i#').value='[COLOR=red]#Replace(getSireList.Name,"'","&rsquo;",'ALL')#[/color]';">
    #getSireList.Name# 
   </li>
  </cfloop>
</ul>
</div>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top