I have some <apex:inputField> tags on my Visualforce page, when I do the save operation, I want to get the value about these input values and check these values.
I use document.getElementById, but can't get the value.
I have some <apex:inputField> tags on my Visualforce page, when I do the save operation, I want to get the value about these input values and check these values.
Check and confirm this by looking at the page source and see what id that salesforce apex has generated for the inputField. If you see in the id 'j_xxx' it means no id defined and salesforce generated the id. In above example, if I didn't define id for myPage, i may have to use document.getElementById('j_id0:myPB:myPBI:myInput').value
If it's an iterated component, for example used in a PageBlockDataTable, salesforce will generate the ids with iteration number included:
xxx:yyy:zzz:0:myInput
xxx:yyy:zzz:1:myInput
xxx:yyy:zzz:2:myInput
...
Hope this helps. Further reading: $Component and it's usage.
Do it like this:
All Answers
What value do you mean? Id, input-value, what tab?
Please elaborate your question.
Hi,
I have some <apex:inputField> tags on my Visualforce page, when I do the save operation, I want to get the value about these input values and check these values.
I use document.getElementById, but can't get the value.
Thank you!
Try to use jQuery, it is very usefull:
Hi,
I have some <apex:inputField> tags on my Visualforce page, when I do the save operation, I want to get the value about these input values and check these values.
Thank you!
Huh?
Hi,
Have a look with my code:
<apex:inputField value="{!First_Name__c}" id="FirstName" />
<script type="text/javascript">
var jq$ = jQuery.noConflict();
var firstName = jq$('FirstName').val();
alert(firstName );
</script>
But can't get the value. I have upload the jquery file in static resource and invoke them in my page.
Do it like this:
Hi ,
I saw the error about "jQuery undefined" on my page. But I have include the js file in my page.
Remove JQuery from your path:
Are the id attributes defined in your apex tags? Use them directly in a hierachical manner with document.getElementById().
Example:
<apex:Page id="myPage">
<apex:PageBlock id="myPB">
<apex:PageBlockItem id="myPBI">
<apex:inputField id="myInput">
</apex:inputField>
</apex:PageBlockItem>
</apex:PageBlock>
</apex:Page>
Get the value in javascript, no jQuery required:
document.getElementById('myPage:myPB:myPBI:myInput').value
Check and confirm this by looking at the page source and see what id that salesforce apex has generated for the inputField. If you see in the id 'j_xxx' it means no id defined and salesforce generated the id. In above example, if I didn't define id for myPage, i may have to use document.getElementById('j_id0:myPB:myPBI:myInput').value
If it's an iterated component, for example used in a PageBlockDataTable, salesforce will generate the ids with iteration number included:
xxx:yyy:zzz:0:myInput
xxx:yyy:zzz:1:myInput
xxx:yyy:zzz:2:myInput
...
Hope this helps. Further reading: $Component and it's usage.
Hi,
I remove the JQuery with my path, then it works, thank you!
Hi,
I have get the value by qjuery, but your method also useful for me.
Thank you!