jQuery, autoNumeric() and id's that contain special characters
The proper syntax for input ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). From http://www.w3.org/TR/html4/types.html
Unfortunately jQuery has some issues with colons(:) and periods(.) and these characters need to be escaped. There are multiple ways to accomplish this. Given the following id="id.name" here are three ways;
- Escaped the period with double backslashes $('#id\\.name').
- Use the document.getElementById( id ) $( document.getElementById( id ) ) - thanks Evan C.
- You can also use the below routine in this manner $( fixId( id ) ). http://docs.jquery.com/Frequently_Asked_Questions
function fixId(myid) { // replaces special characters in id name myid = myid.replace(/\[/g, "\\[").replace(/\]/g, "\\]"); return '#' + myid.replace(/(:|\.)/g,'\\$1'); } // autoNumeric also requires brackets to be escaped
I have modified autoNumeric as of version 1.5.3 to handle special characters internally and with the strip and format functions. Please remember jQuery functions that use the id selector with special characters still needs to be escaped see below.
Please contact me is you have any questions, comments and or suggestions at bob{@}decorplanit.com (remove brackets)