Javascript question

Associate
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
Hi,

I need to check a string for special chars, typically ' " & % this is to be used in an odata query so far I have:

Code:
  if (ProjName.indexOf("&") > 0)
    {
      oDataEndpointUrl += "orb_objectrelationshipSet?$select=orb_accountid,orb_name,orb_objectrelationshipId&$filter=orb_name eq '" + ProjName.replace(/\x26/,"%26")+ "' ";
    }
    else
    {
         oDataEndpointUrl += "orb_objectrelationshipSet?$select=orb_accountid,orb_name,orb_objectrelationshipId&$filter=orb_name eq '" + ProjName + "' ";
    }

But what's an accepted way to check for all of the special chars and replace?

regards,

Matt
 
Associate
OP
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
Thanks for the response.

It works apart from the ' character

Code:
http://A_Server.svc/orb_objectrelationshipSet?$select=orb_accountid,orb_name,orb_objectrelationshipId&$filter=orb_name eq 'Enquiry%2005%2F08%2F14%20Fulham%20(709709)%20-%20O[B]'[/B]Keefe%20Construction'

Why doesn't it convert the ' char?

Matt
 
Associate
OP
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
So use something like:

Code:
ctrelationshipSet?$select=orb_accountid,orb_name,orb_objectrelationshipId&$filter=orb_name eq '" + encodeURIComponent(ProjName.replace(/\x27/,"%27")) + "' ";

Am new to the javascript - well dip in and out as the job requires...

Matt
 
Associate
OP
Joined
27 Jan 2005
Posts
1,324
Location
S. Yorks
Hhhhmmm it doesn't like it.

Copying and pasting the url into a browser returns no results, altering the data to some other data without a ' and it returns data.

Any other ideas?

Matt
 
Back
Top Bottom