Link to home
Start Free TrialLog in
Avatar of brihol44
brihol44

asked on

Convert string to readable variable...

Hello,

I"m looking to convert a string so my jquery script works...

The line is... var myUserID = $('#id_'+myID).val();

but it's not working because my variable "myID" uses other characters besides numbers.

3DC6707A-10-10-11

How can I convert the string so it can be used in this line?

Brian
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

make it

 var myUserID = $('#id_"'+myID +'" ').val();
ASKER CERTIFIED SOLUTION
Avatar of Roman Gherman
Roman Gherman
Flag of Moldova, Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here is a function to escape the selector value that I have found. please test if it works for you:

function escapeStr( str) {
 if( str)
     return str.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g,'\\$1')
 else
     return str;
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi leakim971,

I think in your case will not handle if myID contains '
My opinion is that the best thing that you can do is to escape the string
You right roma1123, I hope there's no << ' >> in the id...