0

我有一个仅捕获以下字段的表单。(见下文)我需要对其进行修改,以便字段“formdesc”(表单描述)仅将下拉列表中选择的内容捕获为文本。但是现在有一个选项 id = [0, 1, 2,3] 用于 JS 中的价格点来计算购买的总金额。

HTML:

   <form action="http://" method="get" name="form">
   <input id="forminv" type="hidden" name="forminv" value="StudentOrg"> (fixed value)
   <input id="formbal" type="hidden" name="formbal" value="0"> (this pulls total from id=tot)
   <input type="text" name="formfname"> (this pulls first name)
   <input type="text" name="formlname"> (this pulls last name)
   <type="text" name="formid"> (this for a student number)
   <select id="apparelType" name="formdesc"> (this should pull value from selection)
   <option selected value="na">Select</option>
   <option value="0">T-Shirt</option> (I need to change this value to “shirt”)
   <option value="1">Shorts</option> (here too, but can't work with JS below)
   <option value="2">Hat</option> (here too)
   <option value="3">Bag</option> (here too)
   <input id="numb" type="number" name="formterm"> (this pulls quantity, and changes total)
   <id="tot"<Total: $0.00&nbsp;>
   <input type="submit" value=" Make a Credit Card Payment">
   </form>

JS:

$(document).ready(function () {
    $('#numb').keyup(function () {
        var appVal = new Array();
        appVal[0] = 15; (if I change this, stops working)
        appVal[1] = 20;
        appVal[2] = 25;
        appVal[3] = 30;
        var cost = 0;
        var fmapVal = $('#apparelType').val();
        if (fmapVal == 'na') {
            alert('Please select an apparel type.');
        } else {
            cost = appVal[fmapVal];
        };
        //alert(cost);
        var getNumb = $('#numb').val();
        var baseTotal = cost * getNumb;
        var getTax = baseTotal * .06;
        var getTotal = baseTotal + getTax;
        $('#tot').html('Total: $' + etTotal.toFixed(2));
        $('#formbal').val(getTotal.toFixed(2));
    });
});
4

1 回答 1

0

这是工作小提琴

更改$('#tot').html()$('#tot').val()

如果您需要所选项目的文本,请使用;

var txt = $('#apparelType').find('option:selected').text();
于 2013-03-10T15:27:25.303 回答