If checkbox is checked add £1.50 to total if not add nothing
Date : March 29 2020, 07:55 AM
will be helpful for those in need Hi I am trying to make a basic form that adds a value of £1.50 on to total price if check box is checked. So i have a user input a price (value for a voucher) they can either pick up or get it delivered - delivery is £1.50. , You need to only add the value if the checkbox is checked. <script type="text/javascript">
function updatesum() {
var deliveryFee = document.form.sum2.checked ? Number(document.form.sum2.value) : 0;
document.form.sum.value = (document.form.sum1.value -0) + deliveryFee;
}
</script>
<form name="form" >
Enter a number:
<input id="voucher" name="cost" />
and another number:
<input type="checkbox" id="deliveryFee" name="fee" value="1.50" checked="checked" >
Their sum is:
<input id="total" name="sum" readonly style="border:0px;">
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$('#voucher,#deliveryFee').change( function() {
var fee = Number( $('#deliveryFee:checked').val() || 0 );
var cost = Number( $('#voucher').val() );
$('#total').val( cost + fee );
});
});
</script>
|
JQuery get selected value from selected dropdowns and add to total
Date : March 29 2020, 07:55 AM
hope this fix your issue In whatever change or click handler you'd like, you can use jQuery's each to get and sum all the values: var total = 0; // Set to some base price
$('.eStore_variation option:selected').each(function() {
var m = /\[\+ \$(\d+\.\d+)\]/.exec(this.value);
if(m !== null) {
total += +m[1];
}
});
var decimalPart = (total - Math.floor(total)) * 100;
$('#theFinalPrice').text('$' + Math.floor(total) + '.' + (decimalPart < 10 ? '0' : '') + decimalPart);
|
How to make some selected items as checked on load in jstree. (selected = "selected" not working)
Date : March 29 2020, 07:55 AM
Does that help In MVC 4 i use jstree. In create operation I have not problem. But in Edit operation, I set true value to some items of treemodel. models are like: , I found solution for my question. .bind("loaded.jstree", function (event, data) {
$('li[selected=selected]').each(function () {
$(this).removeClass('jstree-unchecked').addClass('jstree-checked');
});
});
|
Formhelpers Checked=checked/Selected=selected when editting
Date : March 29 2020, 07:55 AM
Any of those help You can write helper method that returns true, false for both of the cases. view:
<% for p in Pictogram.all %>
<%= radio_button_tag "activity[pictogram_id]", p.id, pictogram_is_true?(p) %>
<% end %>
<% for client in Client.all %>
<%= check_box_tag "activity[client_ids][]", client.id, client_is_true?(client) %>
<% end %>
helper:
def pictogram_is_true?(p)
// query here and return true or false
end
def client_is_true?(client)
// query here and return true or false
end
|
How to get selected items from checked list box and compute their total
Date : March 29 2020, 07:55 AM
should help you out On the button click you will have to look after the checkboxes that are checked and then do the proper math Private Sub Calculate() Handles Button.click
Dim TotalSum As Double = 0
For i = 0 To (CheckedListBox1.Items.Count - 1)
If CheckedListBox1.GetItemChecked(i) = True Then
If CheckedListBox1.Items(i).ToString = "Mango" Then
TotalSum += (100 * tMango)
End If
If CheckedListBox1.Items(i).ToString = "Orange" Then
TotalSum += (100 * tOrange)
End If
End If
Next
End Sub
|