0

I am trying to store a variable from my database into a JavaScript variable with the code below:

var long = "<%=RecordSet.record.get('GPS - Longitude')%>";

The <%= and %> are tags local to the API for the program i am using which is based on JavaScript and runs JavaScript. When i call this data field from the database:

If data is stored as: 91° 6' 5" W The data will not store in variable "long" because of the " character in the string.

If data is stored as: 91° 6' 5 W The data will be stored fine in variable "long".


I know there is a .php function called "addslashes()" which is supposed to remedy this issue when pulling information from a database. I have tried using the "replace" function on the database call with no luck. Is this possible within JavaScript?

JohnFx
  • 34,542
  • 18
  • 104
  • 162
  • Duplicate of http://stackoverflow.com/questions/97578/how-do-i-escape-a-string-inside-javascript-inside-an-onclick-handler? – Michael Myers Jul 08 '11 at 15:18
  • This is not working for me. I have used a replace function to no avail when the field entry contains a " in the database. i have used: `var long = (("<%=RecordSet.record.get('GPS - Longitude')%>").replace('"',"'");` and `var long = (("<%=RecordSet.record.get('GPS - Longitude')%>").replace("\"","'");` and `var long = (("<%=RecordSet.record.get('GPS - Longitude')%>").replace("\x22","'");` with no luck. I have used this format tested with other characters so i know it works. I don't think the database field value is being written in `<%=RecordSet.record.get('GPS - Longitude')%>"`. – Travis McAdams Jul 08 '11 at 20:28

2 Answers2

0

Have you tried using the javascript function 'replace'

string.replace('"', "'");

Or in the php you can use the replace function there

$string=str_replace('"', "'", $string);

Drahcir
  • 11,772
  • 24
  • 86
  • 128
  • Yes i have tried "var long = long.replace('"', "'");" with no luck. It seems that the data from the field is not even being stored in the JS variable "long" because their is a " in the data entry in the database. – Travis McAdams Jul 08 '11 at 17:30
0

The issue has been resolved. It was pertaining to the program i was using. If you are interested here is the link:

http://forums.extensis.com/jforum/posts/list/3695.page