1

I am a beginner in Salesforce. I am trying to implement a code wherein user will get a alert message (some sort of notification ) when a field value is null. Although it will allow the user to save that record. I wrote a VF page. that I will embed with the standard page layout. Let me know if that is the correct approach.

<apex:page standardController="Opportunity" action="{!markread}" extensions="OppExtension">
<script>
      if(!Opportunity.Country__c != null {
          alert("Please fill in the country details");
      }
</script>
</apex:page>

and my extension controller:

public with sharing class OppExtension {
     ApexPages.StandardController controller;
     public OppExtension(ApexPages.StandardController controller) {
         this.controller = controller;
     }
     public void markread() {
         Opportunity o = (Opportunity) controller.getRecord();
         o.MessageShown__c = true;
         update o;
     }
 }
3

1 Answer 1

1

Visualforce page

<!-- Using java script in visualforce page -->
<apex:page extensions="OppExtension">
  <apex:form >
        <apex:pageBlock >
           Input Here  : <apex:inputText id="inptID"/>
                       <apex:commandButton onclick="MyjavaFunction('{!$Component.inptID}')" value=" Submit "/>
        </apex:pageBlock>
  </apex:form>

  <!-- Java script starts Here -->
  <script>
   function MyjavaFunction(ReceiveInputID){

    var inputValue = document.getElementById(ReceiveInputID).value;
         if(inputValue == ''){
            alert('You did not eneter any value in input box');
         } 
         else
            alert(' You entered :: '+inputValue); 
   }
  </script> 

</apex:page>

Here is one code which may be useful for u

Image

1
  • Hi, problem here is ..the layout where I am planning to add this logic is a standard object's page layout. so I am not sure how to use "document.getElementById(ReceiveInputID).value" in this page since I do not know "ReceiveInputID"'s avlue here.
    – Apurbo
    Aug 7, 2014 at 9:54

You must log in to answer this question.

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