Displaying HTML Dropdown Selection in Email Body

0 votes
asked Jul 19, 2017 by rataiczak24

I have a table where you can select certain rows by checking a checkbox and, on a button click, it will bring up an email client and paste those selections into the email body.

I need to have my program work so that it will also paste in the selection from the dropdown list.

However, I have been unsuccessful in my attempts and am having trouble integrating that functionality into my code. How could I display the dropdown selection in my email body?

JavaScript code...the pos_city_selected variable holds the current dropdown list selection:

var input_num;

var pos_city_selected;
var pos_city_selected1;

function updateinput() {
var pos_city = document.getElementById("pos-drop");
pos_city_selected = pos_city.options[pos_city.selectedIndex];
if (pos_city_selected) {
    pos_city_selected1 = true;

$(function($) {
    var RowData = (function(storage, storageKey) {
        var rowData = readFromSession();
        var dataItems = ['loc', 'rp-code', 'sku', 'special-id', 'description', 'quantity', 'unit'];
        var emailDelimiters = {
            'row': '%0D%0A',
            'dataItem': '\xa0\xa0'
        function readFromSession() {
            return JSON.parse(storage.getItem(storageKey) || '{}');
        function writeToSession() {
            storage.setItem(storageKey, JSON.stringify(rowData));
        function writeRow(tr) {
            var $tr = $(tr),
                id = $tr.prop('id');
            if($tr.find('.check').is(':checked')) {
                rowData[id] = {};
                for(var i=0; i<dataItems.length; i++) {
                    rowData[id][dataItems[i]] = $tr.find('.' + dataItems[i]).text();

                input_num = rowData[id].quantity_num = $tr.find('.spinner').val(); // if using HTML5 <input type="number">
            } else {
                delete rowData[id];
        function readRow(tr) {
            // restore tr's checkbox and spinner value from stored data
            var $tr = $(tr),
                id = $tr.prop('id'),
                row = rowData[id];
            if(row) {
                $tr.find('.check').prop('checked', true).end()
                     // .find('.spinner').spinner('value', row.quantity_num); // if using spinner widget
                     .find('.spinner').val(row.quantity_num); // if using HTML5 <input type="number">
        function toEmailString() {
            return $.map(rowData, function(row, id) {
                return $.map(row, window.encodeURIComponent).join(emailDelimiters.dataItem);
        // selectively expose functions as methods of RowData
        return {
            'writeRow': writeRow,
            'readRow': readRow, 
            'toEmailString': toEmailString
    })(window.sessionStorage, 'checkedRowData');

    $('#merchTable').on('change', '.check', function() { // on changing a table row ...
        RowData.writeRow($(this).closest('tr').get(0)); // ... set the corresponding row object in RowData and sessionStorage
    }).on('change', '.spinner', function() { // on leaving a spinner widget
    $('#checkout').on('click', function() { // on clicking the [Checkout] button        

        if (input_num > quantity_num) {
            alert("The entered number cannot be greater than the quantity.");
        } else if (pos_city_selected1 != true) {
            alert("Please select a POS-City from the dropdown list.");
        } else {

        var link = "mailto:me@example.com" + "?subject=" + encodeURIComponent("Order") + "&body=" + RowData.toEmailString();
        window.location.href = link;

    // Call this function on completion of every pagination/search
    function restoreVisibleRows() {
        $('#merchTable tbody tr').get().forEach(RowData.readRow);



HTML select:

<select id="pos-drop" onChange="updateinput();">
    <option selected disabled>POS - City</option>
        <?php foreach($pos->fetchAll() as $city) { ?>
        <option class="pos-city" value="<?php echo $city['POS'];?>"><?php echo $city['POS'];?></option>
        <?php } ?>

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter