+ Start a Discussion

how to pass an attachment to javascript?


hi all,


i am having an issue with passing the attachment to my javascript


here is my onclick function where i am not getting the value of my attachment

<apex:commandButton onclick="sendMail('{!attachment}');return false;" value="Send"  style="margin-left:110px;margin-top:10px;"/>


<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" style="margin-left:50px;margin-top:50px;">



and the controller side my code is:

public Attachment attachment
            if(attachment == null)
                Attachment attachment = new Attachment();
            return attachment;

  but i am not getting the attachment file ..........


i dont know what is going wrong?


please help me..........


any kind of help will be greatly appriciated........


Hi Vishal,
You have not mentioned in your post :-

  • From where are you invoking your custom VF page 
  • Also you need to specify the value of controller or customcontroller for aoex:page tab being used by you.

Do respond to the above queries for me to find the cause of the issue faced by you. 


Why are you trying to pass an attachment to javascript? Why don't you handle everything within the controller?