JayminsFakeAccount JayminsFakeAccount - 3 months ago 9
PHP Question

How to post label value?

Okay so I have a radio button on which my variable values get change through java-script.I am displaying that changed value in

<h>
Tag right.
Now I wants to post this
<h>
Tag value into database. I know
<h>
Tag is not a form element and other solution is using hidden input tag.
Here is my HTML Code:

<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 for that:

<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>


Displaying the value from radiobutton:

<h5><strong>Total</strong>
<h5 id="price" name="finalprice">


<?php
$finalprice=$item_total;
echo $finalprice;
?>
</h5>
</h5>


Now I want this Tag value to be posted in database. Any Solution?

Answer

Try with a hidden input field : Look at this.

$(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);
  });
});

https://jsfiddle.net/rijink121/5vcvt527/4/