?
Solved

Convert string to readable variable...

Posted on 2011-10-09
6
Medium Priority
?
213 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:brihol44
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36940851
make it

 var myUserID = $('#id_"'+myID +'" ').val();
0
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 252 total points
ID: 36940856
Hi,

I don't think there should be a problem with the "-" character because it is allowed.

Here is a list of jQuery special characters: http://www.xinotes.org/notes/note/958/

What you need to do is to find a function to escape the string.
0
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 36940863
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 248 total points
ID: 36946230
If you've really something special : $("[id='id_" + myID + "']").val();
0
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 36947116
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
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36947865
You right roma1123, I hope there's no << ' >> in the id...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Integration Management Part 2
Loops Section Overview
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question