Append .00 to Form Calculated Amount

I have a web form where users can register and pay to attend an event. It is set up so that they can book multiple seats with a single registration. Based on how many seats they book the form will calculate and populate the “amount” field.

The problem is that the amount format does not include the decimal and cents. If the amount is $55 then in the box it would show “55” instead of 55.00

Can anyone offer some insight on what the best way to edit this is so as to achieve this outcome? Thanks!

Amount Field:

<input type="text" name="Amount" id="Amount" class="cat_textbox" />

The page links to this JS file for the form:

(function($){

bookings = function() {

var bookingAmount = 55.00; 	//Booking amount in dollars

	$('#seats').change(function() {
		$('.webform').fadeIn("slow");
		var noOfSeats = $("#seats option:selected").val();  //take the selected option from the dropdown
			$('.hide').fadeOut("slow");
			$('#BookingAllocation').val(noOfSeats); 			//set the number of seats
			totalAmount = bookingAmount * noOfSeats;	
			$('#Amount').val(totalAmount);
		
			for(var index = noOfSeats; index > 0; index--){
				$('.person'+index).fadeIn("slow");
			}
			
		$('.total').html("<span>TOTAL:"+totalAmount+"</span>");
	});
	}
 })(jQuery);

The form has this function in the head of the page:

	function check(input) {
		i = input.value.replace(/[^\d.]/g,'').split(".");
		if(i.length>1) i[0] = i[0] + "." + i[1];
		input.value = parseFloat(i[0]).toFixed(2);
	}

You could just move the check function to the end of the page, just before he tag, and attach that function to an onchange event of the form field. That would be the easiest way to resolve the issue.

$('#Amount').on('change', function () {
    check(this);
});

Thanks for the input Paul! I think I am just missing something…

Here’s the page where you can see the code directly: http://ht.ly/IaROW

Can you take a peak and see if you find what’s wrong? Thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.