如何在$ _POST方法上使用Javascript生成值?

时间:2017-02-12 11:22:31

标签: javascript php

我有三个文本框供应商的价格,加价和总价。 当我在供应商的价格和加价价格文本框中输入价值时,总价格文本框中的值将通过JavaScript生成一个值。

 $('#sell_price, #markup_price').on('input',function() {
   var sell_price = parseInt($('#sell_price').val());
   var markup_price = parseFloat($('#markup_price').val());
$('#total_price').val((sell_price  + ((markup_price/100)*100) ? sell_price + ((markup_price/100)*100) : 0).toFixed(2));
});

如何将总价格的文本框值输入我的$ _POST?enter image description here

HTML代码

 <div class="col-md-4">
     <label for="">Supplier's Price</label>
     <div class="input-group">
       <span class="input-group-addon">
         ₱
       </span>
       <input type="number" class="form-control" name="sell_price" id="sell_price" placeholder="Buying Price Per Unit" step='0.01' value='0.00' placeholder='0.00' required>

     </div>
   </div>

   <div class="col-md-4">
     <label for="">Mark-up Price (In Percentage)</label>
     <div class="input-group">
       <span class="input-group-addon">
         %
       </span>
       <input type="number" class="form-control" name="markup_price" id="markup_price" placeholder="0" required min='1' max='100'>
     </div>
   </div>

       <div class="col-md-4">
        <br>
         <label for="">Total</label>
         <div class="input-group">
           <span class="input-group-addon">
             %
           </span>
           <input type="number" class="form-control" name="total_price" id="total_price" placeholder="0" disabled>
         </div>
       </div>

1 个答案:

答案 0 :(得分:0)

你可以路径:

$('#total_price').val

到此:

function post(path, parameters) {
var form = $('<form></form>');

form.attr("method", "post");
form.attr("action", path);

$.each(parameters, function(key, value) {
    var field = $('<input></input>');

    field.attr("type", "hidden");
    field.attr("name", key);
    field.attr("value", value);

    form.append(field);
});

// The form needs to be a part of the document in
// order for us to be able to submit it.
$(document.body).append(form);
form.submit();
}