0

not able to call javascript function from apex:inputfeild in visualforce page

function getEmail(Emailfeild)
{

               alert('sam');
              var Email = document.getElementById(Emailfeild).value;
              Visualforce.remoting.Manager.invokeAction(
                    
                 '{!$RemoteAction.RetrivialControllerExtension.getAction}',
                    Email, 
                    function(result, event){
                        if (event.status==true) {
                            if(result!=null){
                       document.getElementById('Email ID').innerHTML = 
         result.Email_ID__c;
     }
            }, 
            {escape: true}
        );
    }

VF page

<apex:pageblockSection columns="1">
    <div align="center">
       <apex:inputfield required="true" id="Emailfeild" onclick="getEmail('{!$Component.Emailfeild} )" value="{!IBI_TM_Applicants__c.Email_ID__c}">
         </apex:inputField> 
<apex:pageBlockSectionItem >
3
  • Welcome to Salesforce Stack Exchange (SFSE). Thank you for including code, but there is no actual question in your post. Please take the Tour & look in the Help Center - especially What topics can I ask about here? where it states, '...a question post should include 1) A specific, detailed description of the issue ("it doesn’t work" is not enough to allow the community to help). plus ... 3) and/or the research and work you’ve done so far on the issue.' Please edit your question to add info.
    – Moonpie
    Commented Aug 26, 2021 at 16:48
  • Thank you - that is a good start. However, what exactly does it mean to say, "not able to call javascript function?" > Are you receiving an error? If so, edit again & include a screenshot or a copy/paste of the exact error text. > If you are not receiving an error, are you sure that the JavaScript is not being called? Maybe the JavaScript is not working as expected. Have you checked any debug logs? If so, edit again & include details. > If there are no errors and no logs, include any alerts or console.log()s or anything else you have tried to use to debug, and the results.
    – Moonpie
    Commented Aug 26, 2021 at 17:18
  • 1
    Aside from my answer, there's also a non-zero probability that you may have misspelled something. Make sure you're paying attention to variable and method names, and also note that JavaScript is cAsE-sEnSiTiVe.
    – sfdcfox
    Commented Aug 26, 2021 at 17:39

1 Answer 1

1

There's no need to use ID values here, just use event.target:

<apex:inputfield required="true" onclick="getEmail(event)" value="{!IBI_TM_Applicants__c.Email_ID__c}">

function getEmail(event) {
    var email = event.target.value;
  // ... rest of code
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .