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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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...
var myUserID = $('#id_"'+myID +'" ').val();