好的,所以我有一个单选按钮,我的变量值通过java-script得到改变。我在<h>
Tag右侧显示了更改的值。
现在我想将此<h>
标记值发布到数据库中。我知道<h>
Tag不是表单元素,其他解决方案使用隐藏的输入标记。
这是我的HTML代码:
<label><input type="radio" name="optradio" id="delivery1" value="normal" checked><span class="label label-success">Regular Delivery</span></label><label>If you choose regular Delivery, it will take atleast 4 days time to deliver your product.(There will be no extra charges applied)</label>
<label><input type="radio" name="optradio" id="delivery2" value="fast"><span class="label label-danger">One Day Delivery</span></label>
<label>If you choose One Day Delivery, product(s) will be delivered to you in 24 hours. (40 Rs Will be charged extra.) </label>
JS为此:
<script type="text/javascript">
$(document).ready(function(){
$('#delivery1,#delivery2').change(function(){
price = $('#price').text();
finals = $('#finals').text();
finals1 = $('#HIDDENPRICE').text();
if($('#delivery2').is(':checked')) {
price = (price)*1 + 40;
finals=price;
finals1=price;
} else {
price = (price)*1 - 40;
finals=price;
finals1=price;
}
$('#price').text(price);
$('#finals').text(price);
$('#HIDDENPRICE').text(price);
});
});
</script>
显示radiobutton的值:
<h5><strong>Total</strong>
<h5 id="price" name="finalprice">
<?php
$finalprice=$item_total;
echo $finalprice;
?>
</h5>
</h5>
现在我希望将此Tag值发布到数据库中。任何解决方案?
答案 0 :(得分:0)
尝试隐藏输入字段: 看看这个。
$(document).ready(function(){
$('#delivery1,#delivery2').change(function(){
price = $('#price').text();
if($('#delivery2').is(':checked')) {
price = parseInt(price) + 40;
} else {
price = parseInt(price) - 40;
}
$('#price').text(price);
$('#final_price').val(price);
});
});
答案 1 :(得分:-1)
You can use the ajax call for this.
$("button").click(function(){
$.post("test_post.php",{ finalprice: 'your final price',},
function(data){
alert(data); // the return data on success
});
});
In the test_post.php you can write the database operation and also you can get the value in the post variable like
$_POST['finalprice']