I am actually trying to get the associated label of a apex input tag to do some javascript validations. Here are my tags below:
<apex:outputlabel value="Account" for="NewContactAccountSelect" />
<apex:inputField id="NewContactAccountSelect" value="{!mergeField}" />
<apex:outputlabel value="Last Name" for="NewContactLastName" />
<input type="text" id="NewContactLastName" />
<!-- Other code -->
and there are like mix of HTML input tags and apex:input Tags. I have tried something using jQuery:
var RequiredFields = [];
var NewContactAccountSelect = jQuery("[id$=NewContactAccountSelect]");
var NewContactLastName = jQuery("[id$=NewContactLastName]");
RequiredFields.push(NewContactAccountSelect );
RequiredFields.push(NewContactLastName);
// And to retrive the label for it, I used:
jQuery(RequiredFields).each(function(index,field)
{
jQuery("label[for$="+jQuery(field).attr('id')+"]").html().trim();
//other code to do validation.
}
However,jQuery(NewContactAccountSelect).attr('id')
will not retrieve the exact Id (since, it included the partial Ids as well) for visualforce tags and throws me the following error.
Uncaught Error: Syntax error, unrecognized expression: label[for$=j_id0:j_id106:j_id107:j_id108:j_id117:newContactForm:NewContactAccountSelect]
Any help to get the label of that inputField tag?
Also, another question: Is it possible to remove the partialId's added by salesforce and get the actual Id of form element by using javascript, jQuery etc..,?
jQuery("label[for$="NewContactAccountSelect"]").html().trim();
? Just a thoughtj_idN:
values in the rendered element id attributes?Id
attribute.