+ Start a Discussion

How to fetch a live value from a input field before saving the data?

I have a input field--  <apex:inputField value="{!Registration__c.Event__c}" label="Event" id="Event" />

Now i want to fetch the field value before saving the data into database..

I have called a JScript on clicking of save button..

function Check()
var data=document.getElementById('page:form:block:section:Event');-->differenrt page level ids
alert("Do you want to register for "+data.value.name+"?");

But it is returning "Undefined" !!! I think it is because the data is not saved yet! Please guide...




do this ..................


function Check()
var data=document.getElementById('page:form:block:section:Event');

alert("Do you want to register for "+data.value+"?");


put data.value in place of data.value.name..





I have tried this before but if I put data.value then the alert msg itself not working!! Dont know WHY!!!!!


check this error in inspect element of browser.


Hi ,


This should help you,


function check()
        var data =document.getElementById('{!$Component.event}').value;
        alert("Do you want to register for "+data+"?");


If you have  event inside any other component, then try step by step accessing.

For example, to access a data table withid="tableID"contained in a page block withid="blockID", use the following expression:$Component.blockID.tableID.


Checkout this LINK for more details.



Please mark this post as solved, if it helps you



code which i checked, copy & paste in a separate page and try it


<apex:page standardController="Opportunity">
<apex:form id="myform" >
    function check()
        var test =document.getElementById('{!$Component.order}').value;
<apex:commandButton value="save" onclick="javascript&colon;check()"/>
    <apex:inputField value="{!Opportunity.OrderNumber__c}" id="order"/>


pass anyone Opportunity SFDC Id in the parameter, like apex/testPage?Id=006U000000262zY





Salesforce For All