Auto Radio Button Select - javascript

I am no good with HTML, but I have this script below which I am trying to make correct.
if (form.getAnswerText('total') <=1) {
form.Radioset("radio").checked = 1;
} else {
if (form.getAnswerText('agreement') >=1) {
form.Radioset("radio").checked = 0;
}
The purpose of this script above is as follows.
I have a text field which has a field ID "Total". This text field currently produces a total number.
I have a radio question field, which has a field ID "radio". Within this radio button I have two options "yes(Score 1)" or "no(Score 0)". Both of these options have a radio button score of "0" and "1"
So the script above is supposed to work in this way: If the "total number" is greater than 1, the radio question will select the score "1" and the same if the total less than 1.
Thank you
Joseph

Look if it can help:
You are missing a close parenthesis for you last if
You assign 1
to the radio button when the total is less or equal to 1, maybe you
meant => istead? of <=?

Related

Copy value to another input with a button

I have two input number fields that show total with some jQuery.
Calculate total:
$('form#lines-form-1 :input[type="number"]').change(function() {
var tot = 0;
$('form#lines-form-1 :input[type="number"]').each(function() {
tot += +this.value;
});
$('#tot-qty').text(tot);
});
JSFiddle: https://jsfiddle.net/q3z4w98o/2/
After entering some numbers on form A press Total to show results.
When clicked Copy how to transfer the total value to Form B's first input field?
E.g.
input1 has value 1
input2 has value 1
total = 2
click Copy
input3 gets a value of 2
Use the following code JS Fiddle:
$("button.copy-btn").click(function() {
$('input[name="i3"]').val($("#tot-qty").text());
})
This bit copies the text value inside the #tot-qty span and sets the i3 input value to that when clicking the "Copy" button.

Calculating cumulative price on checkbox checked event and changing on select option

I have a set of check boxes that each and every one is related to a specific row which contains a two drop-downs and a quantity spinner. The first drop-down is for selecting an item and second one for selecting a size of that item based on price. The spinner is for selecting the quantity of the item needed.
I need to count the total price of selected items when a check-box is checked, and on change of the drop-down boxes. Finally, the accumulative price should be displayed in a label for each click.
What I have tried so far is here..
function priceCounting(prcField, qtyField) {
var sum = 0;
var qty = parseInt(qtyField);
$(".chkbxPkgCat:checked").each(function(){
var untPrc = parseFloat(prcField.pop());
sum = sum+ (qty * untPrc);
$(".lblAccumPrice1").text(sum);
});
}
On change of check-box, I am calling the function as follows..
$(".chkbxPkgCat").change(function(){
var itm = $(this).parent().parent().next().next().find(".form-control").val();
var qty = $(this).parent().parent().next().next().next().find(".form-control").text();
priceCounting(itm,qty);
});
Also, this is for item drop down on change event..
$("#itemSlct").change(function () {
priceCounting($("#itemSlct option:selected").text(), $("#itmQty").val());
});
Same way, I am calling this on-change of spinner and the price dropdown.
But I am not getting the correct accumulative price generated and also I need to deduct the price if it is unchecked a check-box which is checked previously. Anyone can be helpful with this please?

Calculate Value of form fields & update Total

I have a form where i need to auto calculate value for checked row.
http://codepen.io/anon/pen/dOBaNN?editors=1010
I am calculating the value for the text field on keyup function but need to do following
Keep All text fields disabled
Second i need to enable only text field related to the checkbox checked
Third Calculate sum for only Checked text field
Right now i am able to calculate value for all checkbox not sure how to map checked checbox to related input and calculate values accordingly.
tried few thing but it keep breaking
1) Too disable your text fields set the disabled property to true.
$(".auto-sum").each(function () {
$(this).prop('disabled', true);
});
2) Enable inputs with checkboxes
$('input[type=checkbox]').on('change', function() {
var id = $(this).val();
var active = $(this).prop('checked');
$('.auto-sum[name=Amount' + id + ']').attr('disabled', !active);
calculateSum();
});
3) Skip disabled inputs when calculating
$(".auto-sum").each(function () {
if ($(this).prop('disabled')) return;
[...]
});
I updated your codepen: http://codepen.io/anon/pen/VmJgxM?editors=1011

Calculate value of text input where checkbox is selected

I am trying to get the value of a text input where the select box next to it is selected.
I've got to somehow join the checkbox and text-input together, so it knows only calculate the value of the text input where the checkbox on the same table row is selected.
An issue is also the fact that none of my checkboxes get the attribute of 'checked' when selected either, so I've not been able to target those which are :checked too.
I suspect my method so far is going a little too over the top so any suggestions are welcome.
http://rlpetproducts2.designlocker.co.uk/index.php?route=product/product&product_id=251
$('table.table-bordered input[type="checkbox"]').change(function () {
$(this).toggleClass('jordan');
});
$('#button-cart').hover(function () {
var sum = 0;
$('table.table-bordered input[type="checkbox"]:checked').each(function() {
$('table.table-bordered input[type="text"].jordan').each(function() {
sum += Number($(this).val());
});
});
console.log(sum);
});
The Goal: on 'Add to Basket' click, check at least one of the selected options is selected (else alert), if one is selected, calculate the total quantity from the inline input fields (where checkbox is selected) (for now simply alert the quantity total).
In this example, the value to be alerted would be 5.
Untested but it should work like this:
$('#button-cart').hover(function () {
var parent, sum = 0;
$('table.table-bordered input[type="checkbox"]:checked').each(function() {
// get current row
parent = $(this).closest('tr');
// in row find input and add the value
sum += parseFloat(parent.find('input[type="text"].jordan').val());
});
console.log(sum);
});

how to turn on error messages and turn off depending on what the user inputs using jquery

I am trying to validate a form and I want to be able to toggle the error messages off and on when the user inputs a value into the form field. This is what I have so far that is not working:
$('#uTagNum').blur(function() {
var tagNumber=$(this).val();
if (tagNumber.length < 9){
$('#tagErrorMsg').html('<div>Invalid format.Hover over Tag Number column name to see valid formats</div>');
$('#uTagNum').blur(function() {
$('#tagErrorMsg').hide();
});
});
If the user puts in "Dgfh578" and it is not 9 characters or digits long then I need the tagErrorMsG to appear below the field. If the user deletes what they typed the the error message will disappear unless again they type less then 9 characters or digits.
You have some syntax errors and you probably don't want to use hide(), just clear the HTML for #tagErrorMsg. Have a look at this example - http://jsfiddle.net/jayblanchard/mqeCj/
$('#uTagNum').blur(function () {
var tagNumber = $(this).val();
console.log(tagNumber);
if (tagNumber.length < 9) {
$('#tagErrorMsg').html('<div>Invalid format.Hover over Tag Number column name to see valid formats</div>');
} else {
$('#tagErrorMsg').html('');
}
});

Categories