Email form with both attach attachment button and send email button in it

Posted on 2006-05-28
Last Modified: 2012-05-05
I am slowly figuring out sending emails with attachments using CDO.
I have an email form with usual to, from, subject and message inputs and then have a button with a value "upload attachment" when clicked this submits the form to the next page where the user browses for and uploads a file attachment and then submits this file for attachment with the email.

How can I include a second button on the original email form with a value"Send Email" for the user to click when they do not want to attach any attachments just simply send the email form as is?

Thanks for your help.
Question by:rabbits2
    LVL 7

    Accepted Solution

    add to your form
    <input type='hidden' name='reallysendemail' value='false' />
    <input type='submit' value='Send Email' onClick='document.forms[0].reallysendemail.value="true"; return true;' />

    (or possible return false)

    when you submit to your email sending, attachment adding page, query the value of reallysendemail.  if its true, send the email, otherwise add an attachment.

    alternative is change the action location of the form, and redirect to a different pge entirely.

    Author Comment

    That makes sense, but could you please explain in a bit more detail:

    1. Why 'or possible return false'

    I have tried this idea by have the
    <input type='hidden' name='reallysendemail' value='false' />
    <input type='submit' value='Send Email' onClick='document.forms[0].reallysendemail.value="true"; return true;' />
    and then on the second page:

    sendornot = Request.Form ("reallysendemail")
    If sendornot ="true" Then

    'send email using CDO
    Response.Write "You have successfully sent the email"


    'write the page including the file attachment form

    But whenever I click on the 'Send Email' button on the first page I seem not to be changing the value of 'reallysendemail' as the file attachment form writes on the second page.
    Could it be to do with my form name on the first page being 'formemail' and therfore perhaps I must change the form name in this line:
    <input type='submit' value='Send Email' onClick='document.forms[0].reallysendemail.value="true"; return true;' />

    <input type='submit' value='Send Email' onClick='document.forms[formemail].reallysendemail.value="true"; return true;' />

    Just tested that and I am still getting the value of reallysendemail as 'false' when I press the 'Send Email' button.

    Any ideas, thanks

    Author Comment

    This works:

    <input type='hidden' name='reallysendemail' value='' />
                          <input type='submit' value='Send Email' onClick='document.formemail.reallysendemail.value="true"; return true;' />

    LVL 7

    Expert Comment

    yeah, the javascript was a bit spotty.  i can never remember if you return true to make the script continue, or false to make the script continue.  also, if u have more than one form, it may not be forms[0], so naming the form is a good idea.  glad it works.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now