I need to create a javascript where in if the save button is pressed it will show a confirmation pop up if the user want's to save it or no. Now my only problem is I don't know how to call a input field to the javascript function. For example I have this input field <apex:inputField value="{!myVar.item.SPR_Price__c}"> How can I call it to the Javascript function?. Thanks in advance.


Just add an ID to your apex:inputField and then access it in javascript using

var spr_price= document.getElementById("input_spr_price");

You can then access your value using

  • Hi @PierrickBrun. Well I already tried that but it does not work. The thing is my input field is. inside a <apex:form> then an <apex:pageBlock> then <apex:pageBlockSection>, then <Apex:Column>
    – JMDF
    Oct 20 '16 at 18:55
  • Is your javascript button part of your visualforce page or is it called by a custom button ? Note that Salesforce adds prefix to the ID (eg. id="j_id0:j_id1:test") So you could want tu use document.querySelectorAll("[id$=test]") and iterate over the elements. Look at this JsFiddle : jsfiddle.net/BBaFa/2 Oct 21 '16 at 9:18
  • Also querySelectorAll doesn't work on IE 8 w3schools.com/jsref/met_document_queryselectorall.asp Oct 21 '16 at 9:20
  • Yes my javascript is part of the visualforce page and I will call it on the <apex:commandbutton onlick="Javascript function()">
    – JMDF
    Oct 21 '16 at 12:57
  • Doesn't using <apex:commandbutton onlick="Javascript function({!myVar.item.SPR_Price__c})"> work ? Oct 21 '16 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.