0

How to get the name of Account as alert in visualforce page. I tried getting name of the user using below code.

<apex:page standardController="Account" recordSetVar="Accounts" sidebar="False" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Hello {!$User.FirstName}!">
            <apex:pageBlockSection title="Details">
            <apex:pageBlockTable value="{!Accounts}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.type}"/>
                <apex:column value="{!a.Website}"/>
                <apex:column value="{!a.NumberOfEmployees}"/>
                <apex:column headerValue="Details">
                    <apex:commandButton value="Details" onClick="alert('{!$User.FirstName}')"/></apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Can anyone help me displaying Name of the Account on alert.

1

Try to use onClick="alert('{!a.name}')" instead of onClick="alert('{!$User.FirstName}')".

  • Thanks that's working :) – Sai Vineeth Maddula Feb 14 at 8:43
  • @SaiVineethMaddula If my answer helped resolve your issue, please mark the answer as accepted for the benefit of others. – Saroj Bera Feb 14 at 9:24
0

Also you can try like this for picklist, but you need the include jquery library

Like This:

<apex:includeScript value="{!$Resource.Jquery}"/>

Below Code VF Page:

<apex:page standardController="Account" extensions="DoesntMatterBro" standardStylesheets="false">

     <apex:selectList id="SelectedVal" value="{!Name}" size="1">
         <apex:selectOptions value="{!Options}"/>
     </apex:selectList>
     <apex:commandButton action="{!null}" reRender="noneurvey" value="Save" id="theButton"/>
      </apex:pageBlockSection>


Below code Jquery:

 <script>
        $(document).ready(function() { 
            jQuery("[id$='SelectedVal']").addClass('SelectedVal');
            jQuery("[name$='body']").addClass('jumbotron');
            $(document).on("click", "[id$=theButton]", function() {

                a = $('.SelectedVal').val();
                alert(a);

           });     
        });
    </script>

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.