The id‘s on the page I’m working on are defined a group of colon-separated strings (e.g. thisPage:theForm:address1content). I can’t change this format and I’m trying to do some validation on address1content.
I’m trying to pass the id for address1content to a function and do a replaceAll and replace the : with \\: so I can do a $(id). It isn’t working.
Here’s what I have:
function validateContent(text) {
var hardCoded=$('#thisPage\\:theForm\\:address1content').val();
alert(hardCoded);
var regex = new RegExp(":", 'g');
replacedText = text.replace(regex, '\\:');
alert(replacedText);
foundElement= $(replacedText).val();
alert(foundElement);
}
Right now the variable hardCoded is coming through correctly but I’d like to be able to do this dynamically so I can validate multiple fields.
I pasted a simplified version in a fiddle if that helps: http://jsfiddle.net/nYeJH/
Due to my comment, real reason was the forgotten
#in the text.http://jsfiddle.net/nYeJH/6