Web Analytics Made Easy -
StatCounter E-mail Button - CodingForum

Announcement

Collapse
No announcement yet.

E-mail Button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • E-mail Button

    I have a dynamic table that acts as a results page. At the bottom I want to create an "e-mail" button that will open up the local computer's e-mail client with a specific e-mail address, and a subject line that uses one of the fields from the recordset that the page returned. The recordset has a set of navigation bars to handle multiple pages but I want this link to appear at the bottom of every page. Here's my code for the page:

    <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/GENRET.asp" -->
    <%
    var ship_detail_lookup__varShipNum = "37232";
    if (String(Request.QueryString("SHIP_NUM")) != "undefined" &&
    String(Request.QueryString("SHIP_NUM")) != "") {
    ship_detail_lookup__varShipNum = String(Request.QueryString("SHIP_NUM"));
    }
    %>
    <%
    var ship_detail_lookup__varShipNum = "0";
    if (String(Request.QueryString("SHIP_NUM")) != "undefined" &&
    String(Request.QueryString("SHIP_NUM")) != "") {
    ship_detail_lookup__varShipNum = String(Request.QueryString("SHIP_NUM"));
    }
    %>
    <%
    var ship_detail_lookup = Server.CreateObject("ADODB.Recordset");
    ship_detail_lookup.ActiveConnection = MM_GENRET_STRING;
    ship_detail_lookup.Source = "SELECT ship_ln.ship_num, ship_ln.tote, ship_ln.vsn, gm_sku.size_cd, ship_ln.ve_cd, ship_ln.sku_num, gm_itm.des1, ship_ln.ship_qty, ship_ln.ret_prc FROM ship_ln, gm_itm, gm_sku WHERE ship_ln.ship_num = '"+ ship_detail_lookup__varShipNum.replace(/'/g, "''") + "' and ship_ln.itm_cd = gm_itm.itm_cd and ship_ln.sku_num = gm_sku.sku_num ORDER BY ship_ln.tote, ship_ln.ve_cd, ship_ln.sku_num";
    ship_detail_lookup.CursorType = 0;
    ship_detail_lookup.CursorLocation = 2;
    ship_detail_lookup.LockType = 1;
    ship_detail_lookup.Open();
    var ship_detail_lookup_numRows = 0;
    %>
    <%
    var Repeat1__numRows = 10;
    var Repeat1__index = 0;
    ship_detail_lookup_numRows += Repeat1__numRows;
    %>
    <%
    // *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

    // set the record count
    var ship_detail_lookup_total = ship_detail_lookup.RecordCount;

    // set the number of rows displayed on this page
    if (ship_detail_lookup_numRows < 0) { // if repeat region set to all records
    ship_detail_lookup_numRows = ship_detail_lookup_total;
    } else if (ship_detail_lookup_numRows == 0) { // if no repeat regions
    ship_detail_lookup_numRows = 1;
    }

    // set the first and last displayed record
    var ship_detail_lookup_first = 1;
    var ship_detail_lookup_last = ship_detail_lookup_first + ship_detail_lookup_numRows - 1;

    // if we have the correct record count, check the other stats
    if (ship_detail_lookup_total != -1) {
    ship_detail_lookup_numRows = Math.min(ship_detail_lookup_numRows, ship_detail_lookup_total);
    ship_detail_lookup_first = Math.min(ship_detail_lookup_first, ship_detail_lookup_total);
    ship_detail_lookup_last = Math.min(ship_detail_lookup_last, ship_detail_lookup_total);
    }
    %>
    <%
    // *** Recordset Stats: if we don't know the record count, manually count them

    if (ship_detail_lookup_total == -1) {

    // count the total records by iterating through the recordset
    for (ship_detail_lookup_total=0; !ship_detail_lookup.EOF; ship_detail_lookup.MoveNext()) {
    ship_detail_lookup_total++;
    }

    // reset the cursor to the beginning
    if (ship_detail_lookup.CursorType > 0) {
    if (!ship_detail_lookup.BOF) ship_detail_lookup.MoveFirst();
    } else {
    ship_detail_lookup.Requery();
    }

    // set the number of rows displayed on this page
    if (ship_detail_lookup_numRows < 0 || ship_detail_lookup_numRows > ship_detail_lookup_total) {
    ship_detail_lookup_numRows = ship_detail_lookup_total;
    }

    // set the first and last displayed record
    ship_detail_lookup_last = Math.min(ship_detail_lookup_first + ship_detail_lookup_numRows - 1, ship_detail_lookup_total);
    ship_detail_lookup_first = Math.min(ship_detail_lookup_first, ship_detail_lookup_total);
    }
    %>
    <% var MM_paramName = ""; %>
    <%
    // *** Move To Record and Go To Record: declare variables

    var MM_rs = ship_detail_lookup;
    var MM_rsCount = ship_detail_lookup_total;
    var MM_size = ship_detail_lookup_numRows;
    var MM_uniqueCol = "";
    MM_paramName = "";
    var MM_offset = 0;
    var MM_atTotal = false;
    var MM_paramIsDefined = (MM_paramName != "" && String(Request(MM_paramName)) != "undefined");
    %>
    <%
    // *** Move To Record: handle 'index' or 'offset' parameter

    if (!MM_paramIsDefined && MM_rsCount != 0) {

    // use index parameter if defined, otherwise use offset parameter
    r = String(Request("index"));
    if (r == "undefined") r = String(Request("offset"));
    if (r && r != "undefined") MM_offset = parseInt(r);

    // if we have a record count, check if we are past the end of the recordset
    if (MM_rsCount != -1) {
    if (MM_offset >= MM_rsCount || MM_offset == -1) { // past end or move last
    if ((MM_rsCount % MM_size) != 0) { // last page not a full repeat region
    MM_offset = MM_rsCount - (MM_rsCount % MM_size);
    } else {
    MM_offset = MM_rsCount - MM_size;
    }
    }
    }

    // move the cursor to the selected record
    for (var i=0; !MM_rs.EOF && (i < MM_offset || MM_offset == -1); i++) {
    MM_rs.MoveNext();
    }
    if (MM_rs.EOF) MM_offset = i; // set MM_offset to the last possible record
    }
    %>
    <%
    // *** Move To Record: if we dont know the record count, check the display range

    if (MM_rsCount == -1) {

    // walk to the end of the display range for this page
    for (var i=MM_offset; !MM_rs.EOF && (MM_size < 0 || i < MM_offset + MM_size); i++) {
    MM_rs.MoveNext();
    }

    // if we walked off the end of the recordset, set MM_rsCount and MM_size
    if (MM_rs.EOF) {
    MM_rsCount = i;
    if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount;
    }

    // if we walked off the end, set the offset based on page size
    if (MM_rs.EOF && !MM_paramIsDefined) {
    if ((MM_rsCount % MM_size) != 0) { // last page not a full repeat region
    MM_offset = MM_rsCount - (MM_rsCount % MM_size);
    } else {
    MM_offset = MM_rsCount - MM_size;
    }
    }

    // reset the cursor to the beginning
    if (MM_rs.CursorType > 0) {
    if (!MM_rs.BOF) MM_rs.MoveFirst();
    } else {
    MM_rs.Requery();
    }

    // move the cursor to the selected record
    for (var i=0; !MM_rs.EOF && i < MM_offset; i++) {
    MM_rs.MoveNext();
    }
    }
    %>
    <%
    // *** Move To Record: update recordset stats

    // set the first and last displayed record
    ship_detail_lookup_first = MM_offset + 1;
    ship_detail_lookup_last = MM_offset + MM_size;
    if (MM_rsCount != -1) {
    ship_detail_lookup_first = Math.min(ship_detail_lookup_first, MM_rsCount);
    ship_detail_lookup_last = Math.min(ship_detail_lookup_last, MM_rsCount);
    }

    // set the boolean used by hide region to check if we are on the last record
    MM_atTotal = (MM_rsCount != -1 && MM_offset + MM_size >= MM_rsCount);
    %>
    <%
    // *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

    // create the list of parameters which should not be maintained
    var MM_removeList = "&index=";
    if (MM_paramName != "") MM_removeList += "&" + MM_paramName.toLowerCase() + "=";
    var MM_keepURL="",MM_keepForm="",MM_keepBoth="",MM_keepNone="";

    // add the URL parameters to the MM_keepURL string
    for (var items=new Enumerator(Request.QueryString); !items.atEnd(); items.moveNext()) {
    var nextItem = "&" + items.item().toLowerCase() + "=";
    if (MM_removeList.indexOf(nextItem) == -1) {
    MM_keepURL += "&" + items.item() + "=" + Server.URLencode(Request.QueryString(items.item()));
    }
    }

    // add the Form variables to the MM_keepForm string
    for (var items=new Enumerator(Request.Form); !items.atEnd(); items.moveNext()) {
    var nextItem = "&" + items.item().toLowerCase() + "=";
    if (MM_removeList.indexOf(nextItem) == -1) {
    MM_keepForm += "&" + items.item() + "=" + Server.URLencode(Request.Form(items.item()));
    }
    }

    // create the Form + URL string and remove the intial '&' from each of the strings
    MM_keepBoth = MM_keepURL + MM_keepForm;
    if (MM_keepBoth.length > 0) MM_keepBoth = MM_keepBoth.substring(1);
    if (MM_keepURL.length > 0) MM_keepURL = MM_keepURL.substring(1);
    if (MM_keepForm.length > 0) MM_keepForm = MM_keepForm.substring(1);
    %>
    <%
    // *** Move To Record: set the strings for the first, last, next, and previous links

    var MM_moveFirst="",MM_moveLast="",MM_moveNext="",MM_movePrev="";
    var MM_keepMove = MM_keepBoth; // keep both Form and URL parameters for moves
    var MM_moveParam = "index";

    // if the page has a repeated region, remove 'offset' from the maintained parameters
    if (MM_size > 1) {
    MM_moveParam = "offset";
    if (MM_keepMove.length > 0) {
    params = MM_keepMove.split("&");
    MM_keepMove = "";
    for (var i=0; i < params.length; i++) {
    var nextItem = params[i].substring(0,params[i].indexOf("="));
    if (nextItem.toLowerCase() != MM_moveParam) {
    MM_keepMove += "&" + params[i];
    }
    }
    if (MM_keepMove.length > 0) MM_keepMove = MM_keepMove.substring(1);
    }
    }

    // set the strings for the move to links
    if (MM_keepMove.length > 0) MM_keepMove = Server.HTMLEncode(MM_keepMove) + "&";
    var urlStr = Request.ServerVariables("URL") + "?" + MM_keepMove + MM_moveParam + "=";
    MM_moveFirst = urlStr + "0";
    MM_moveLast = urlStr + "-1";
    MM_moveNext = urlStr + (MM_offset + MM_size);
    MM_movePrev = urlStr + Math.max(MM_offset - MM_size,0);
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Shipment Details</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="/css/wss_styles.css" rel="stylesheet" type="text/css">
    </head>

    <body>
    <p>&nbsp;</p>

    <table width="453" border="0">
    <tr>
    <td width="165"><span class="TableHeader">Shipment #: </span></td>
    <td class="fz" width="278"><strong class="TableRowName"><%=(ship_detail_lookup.Fields.Item("SHIP_NUM").Value)%></strong></td>
    </tr>
    </table>
    <table border="2" cellpadding="2" cellspacing="2">
    <tr>
    <td><div align="center" class="TableColumnName"><strong>Tote # </strong></div></td>
    <td><div align="center" class="TableColumnName">VSN:</div></td>
    <td><div align="center" class="TableColumnName">Size:</div></td>
    <td><div align="center" class="TableColumnName">Vendor:</div></td>
    <td><div align="center" class="TableColumnName">SKU:</div></td>
    <td><div align="center" class="TableColumnName">Description:</div></td>
    <td><div align="center" class="TableColumnName">Qty.</div></td>
    <td><div align="center" class="TableColumnName">Retail Price: </div></td>
    </tr>
    <% while ((Repeat1__numRows-- != 0) && (!ship_detail_lookup.EOF)) { %>
    <tr>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("TOTE").Value)%></td>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("VSN").Value)%></td>
    <td><span class="Results"><%=(ship_detail_lookup.Fields.Item("SIZE_CD").Value)%></span></td>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("VE_CD").Value)%></td>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("SKU_NUM").Value)%></td>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("DES1").Value)%></td>
    <td class="HighLite"><%=(ship_detail_lookup.Fields.Item("SHIP_QTY").Value)%></td>
    <td class="Results"><%=(ship_detail_lookup.Fields.Item("RET_PRC").Value)%></td>
    </tr>
    <%
    Repeat1__index++;
    ship_detail_lookup.MoveNext();
    }
    %>
    </table>
    <table border="0" width="50%" align="center">
    <tr>
    <td width="23%" align="center">
    <div align="center">
    <% if (MM_offset != 0) { %>
    <a href="<%=MM_moveFirst%>"><img src="images/First.gif" width="18" height="13" border=0></a>
    <% } // end MM_offset != 0 %>
    </div></td>
    <td width="31%" align="center">
    <div align="center">
    <% if (MM_offset != 0) { %>
    <a href="<%=MM_movePrev%>"><img src="images/Previous.gif" width="14" height="13" border=0></a>
    <% } // end MM_offset != 0 %>
    </div></td>
    <td width="23%" align="center">
    <div align="center">
    <% if (!MM_atTotal) { %>
    <a href="<%=MM_moveNext%>"><img src="images/Next.gif" width="14" height="13" border=0></a>
    <% } // end !MM_atTotal %>
    </div></td>
    <td width="23%" align="center">
    <div align="center">
    <% if (!MM_atTotal) { %>
    <a href="<%=MM_moveLast%>"><img src="images/Last.gif" width="18" height="13" border=0></a>
    <% } // end !MM_atTotal %>
    </div></td>
    </tr>
    </table>
    <p>&nbsp; Records <span class="Results"><%=(ship_detail_lookup_first)%></span> to <span class="Results"><%=(ship_detail_lookup_last)%></span> of <span class="Results"><%=(ship_detail_lookup_total)%></span> </p>
    </body>
    </html>
    <%
    ship_detail_lookup.Close();
    %>

  • #2
    Whewwww;

    That's alot of code not to be placed in code tags.

    .....Willy

    Comment


    • #3
      Well,

      I would say you create a button like so:
      Code:
      <input type="button" value="E-mail" onClick="emailInfo()">
      You can put that button wherever you like on this page.

      Then you need that Javascript function:
      Code:
      <script>
       function emailInfo() {
        var emailAddress = ""; //put the email address here
        var emailSubject = ""; //put the subject here
      
        var location = "mailto:"+emailAddress+"?subject="+emailSubject;
        var win = window.open(location); // Open a New Window
       }
      </script>
      I'm not sure how you want to determine what fields will be going into the subject line or what email address, etc... so I've left that open for you.

      You may alternatively wish to have the function accept parameters and include those parameters in the mailto thing...

      You may also wish to take into account that some people use hotmail and similar web-based email clients, and therefore this is just annoying for those users. But as you wish...

      Hope that helps,
      Sadiq.

      Comment


      • #4
        Got it working, however I can't seem to pass the variable correctly to the subject. I'm trying to pass the "ship_num" value returned from the recordset, but I think my syntax is screwed up?

        <script>
        function emailInfo() {
        var emailAddress = "[email protected]"; //put the email address here
        var emailSubject = "Shipment # "+ship_detail_lookup.Fields.Item("SHIP_NUM").Value; //put the subject here

        var location = "mailto:"+emailAddress+"?subject="+emailSubject;
        var win = window.open(location); // Open a New Window
        }
        </script>

        Comment


        • #5
          I'm not sure, but it looks like you're using ASP?

          If I'm thinking correctly, you'd have to change your code as follows:

          Code:
          <script>
          function emailInfo() {
          var emailAddress = "[email protected]"; //put the email address here
          var emailSubject = "Shipment # "+<% ship_detail_lookup.Fields.Item("SHIP_NUM").Value %>; //put the subject here
          
          var location = "mailto:"+emailAddress+"?subject="+emailSubject;
          var win = window.open(location); // Open a New Window
          }
          </script>
          Ensuring to include the <% %> tags. I think that may fix your problem. You have to ensure you understand the split between Serverside/Javascript and Clientside/Javascript.

          Hope that helps,
          Sadiq.

          Comment


          • #6
            I changed my code to do this with a link however it is still not grabbing the variable for "ship_num"?

            <a href="mailto:[email protected]?Subject=Shipment #"+<% ship_detail_lookup.Fields.Item("SHIP_NUM").Value %>"&CC=&BCC=&Body=The following are corrections:">Corrections</a></td>

            Comment


            • #7
              just embed or insert the server-side code just like you are inserting server-side codes inside html tags

              <a href="mailto:[email protected]?Subject=Shipment #<% ship_detail_lookup.Fields.Item("SHIP_NUM").Value%>&CC=&BCC=&Body=The%20following%20are%20corrections%3A">Corrections</a>

              And you have to escape (encode) the space and colon symbol so that they are transferred correctly to the email client.
              Last edited by glenngv; Feb 16, 2004, 11:39 PM.
              Glenn
              vBulletin Mods That Rock!

              Comment


              • #8
                I'm still not getting the value of "ship_num" in the subject of my e-mail message, here is my relevant code"

                This page has a recordset that it is retrieving and the "ship_num" is part of that, but the "ship_num" value is also being passed to the page in the querystring.

                <a href="mailto:[email protected]?Subject=Shipment #<% ship_detail_lookup.Fields.Item("SHIP_NUM").Value%>&CC=&BCC=&Body=The%20following%20are%20corrections %3A">Corrections</a>

                ...how do I get the value for "ship_num" tp appear in the subject line?

                Comment


                • #9
                  <a href="mailto:[email protected]?Subject=Shipment%20#<% ship_detail_lookup.Fields.Item("SHIP_NUM").Value%>&CC=&BCC=&Body=The%20following%20are%20corrections %3A">Corrections</a>

                  Comment


                  • #10
                    I replaced the space with those characters but that wasn't the problem, the e-mail client is opening correctly, it's just not grabbing the variable value for "ship_num". All I get in the Subject line is "Shipment #" and thats it...

                    Comment


                    • #11
                      <% =ship_detail_lookup.Fields.Item("SHIP_NUM").Value%>

                      If still no joy, try viewing the html source to see if the mailto url really contains the ship_num value.
                      Glenn
                      vBulletin Mods That Rock!

                      Comment


                      • #12
                        That was the problem, I must have looked at that for two days, thanks.

                        Comment

                        Working...
                        X