Skip to content

Instantly share code, notes, and snippets.

@jkentjnr
Last active August 29, 2015 14:21
Show Gist options
  • Save jkentjnr/b775f63e6898dbd57f3f to your computer and use it in GitHub Desktop.
Save jkentjnr/b775f63e6898dbd57f3f to your computer and use it in GitHub Desktop.
Blog - USING JQUERY TO REFERENCE AN INPUT IN VISUALFORCE
<apex:form id="form">
<apex:pageBlock id="blockContact" mode="edit">
<apex:pageBlockSection id="blockDetails" title="Details">
<apex:inputField id="inputContactName" value="{!Contact.Name}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<input id="j_id0:form:blockContact:blockDetails:inputContactName" type="text" />
var o = document.getElementById('j_id0:form:blockContact:blockDetails:inputContactName');
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<script type="text/javascript">
j$ = jQuery.noConflict();
j$(document).ready(function() {
// The dollar sign after the id attribute tells jQuery to return any elements
// with an id that end in 'ContactName'
var o = j$('input[id$=ContactName]').val();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment