You need to sign in to do that
Don't have an account?
admintrmp
Get a lookup id via JS
I need to get a lookup ID from an inputField component via JavaScript but the field with the lookup ID looks different and I can't rely on setting a static component ID to get it.
Is there anyway I can do this? I'm developing a managed app, so I need to be able to make sure I can get the ID of the field dynamically.
I made a Javascript function to solve this problem just in case anyone wants it:
function getLookUpId(str) {
return document.getElementById(str+'_lkid').value;
}
For those using jQuery:
function getLookUpId(str) {
str = str+'_lkid';
str = str.replace(/:/g, '\\:');
return jQuery('#'+str).val();
}
All Answers
I made a Javascript function to solve this problem just in case anyone wants it:
function getLookUpId(str) {
return document.getElementById(str+'_lkid').value;
}
For those using jQuery:
function getLookUpId(str) {
str = str+'_lkid';
str = str.replace(/:/g, '\\:');
return jQuery('#'+str).val();
}
I'm not sure what you're using the data for or where it goes beyond the context of this snippet, but if you're passing anything back to VF from JS this appears to create a XSS vulnerability based on the fact that the value retrieved by JS can be manipulated in the browser. Just a heads up if this is a commercial app that you plan to submit for an AppExchange security review, we've seen similar code get flagged by the security scan.
I suppose your right.
Perhaps the following snippet would be a better idea?
function cloneId(str){ return str; } function getLookUpId(str) { var recordId = cloneId(document.getElementById(str+'_lkid').value); return recordId; }
param str‘s meaning?