Select to view content in your preferred language

Query has no results return depend on the data?

642
1
Jump to solution
09-30-2014 10:31 AM
MayJeff
Deactivated User

Here is my query where clause:

query1.where = "(name) ='" + dom.byId("SUB").value + "'";

When I run a query, 90% query will return results except if the data has "  ' ".  For example, if my data has a name called "BRIAN'S ESTATES" then query won't return any results even though you enter the exact same name.  Got ideas to change the where clause?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jeff,

  This is because you will have to escape your single quote in the entered value for the expression to work.

So you have to check if the dom.byId("SUB").value has a single quote and if so then use the replace method to escape it.

        var usrVal = dom.byId("SUB").value.toString();

        if(usrVal.indexOf("'") > -1){

          usrVal = usrVal.replace(/'/g,"''");

        }

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Jeff,

  This is because you will have to escape your single quote in the entered value for the expression to work.

So you have to check if the dom.byId("SUB").value has a single quote and if so then use the replace method to escape it.

        var usrVal = dom.byId("SUB").value.toString();

        if(usrVal.indexOf("'") > -1){

          usrVal = usrVal.replace(/'/g,"''");

        }