Hi. I'm new at Javascript.

I'm trying to generate a customised WORLDPAY (similar to Paypal) payment form.

I have this form I picked up. I basically want the javascript to take a text user-input amount and then add on a 'card fee', which is assigned by either one of two sums (user selected radio box).

Of the two radio boxes assigning the 'card fee' The first choice would be a fixed variable of 1, and the other being of percentage variable = 3% of the 'user-input'.

Then when a user presses a submit button 'Calculate Total' it should generate the sum of the two - the user input + card fee.

This coding below was provided by the WORLDPAY support site and I have tried my best to customise it. I can get the 'CALCULATE TOTAL' to work locally/client-side on my Mac/Win7 and provide me with a correct numerical result (incl. fixed fee or %).

However, when I transfer the same page/file online the 'Total' box displays the "N.aN" when you click on 'Calculate Total' - which I gather means Not A Number??? But why does it work locally and not remotely.

Can anyone help? And thanks in advance!

<form action="https://secure-test.worldpay.com/wcc/purchase" method=post name=BuyForm">

<!-- The next two functions round numbers to numerical formatting. They do not need to be altered when adding or removing products. -->
function roundOff(value, precision)
	return types(value,1,precision);
function types(X, M, N) 
	var T, S=new String(Math.round(X*Number("1e"+N)))

	while (S.length<M+N) S='0'+S
	var y = S.substr(0, T=(S.length-N));
		y += '.' + S.substr(T, N);
	return y;
<!-- This function checks for empty quantities. It does not need to be altered when adding or removing products. -->
function CheckNull(value)
	if (value == "")
		value = "0";

	return value;
<!-- This function defines the card type and fee. It does not need to be altered when adding or removing products. -->
function typeOfCarriage(x,card_charge)
	x.card_type.value = card_charge;
<!-- This function addeds the card fee to the original amount. -->
function calculate(x)
	basicprice = calc(x);   
    var percent = (basicprice * 0.03);
	if(Number(basicprice) > 0)
		switch (x.card_type.value)
			case "debit_card" :
				x.postage_and_packaging.value = 1.00;
			case "credit_card" :
				x.postage_and_packaging.value = percent;
			default :
				x.postage_and_packaging.value = 0;
		x.amount.value = Number(basicprice) + Number(x.postage_and_packaging.value);

		x.amount.value = "0";
	x.amount.value = roundOff(x.amount.value,2);
<!-- The standard amount, exluding card fee is calculated here. It does not need to be altered. -->
function calc(x)
	x.amount.value = 0;
	var y = x.price.length;
	var z = x.qty.length;
	var a = Number(x.amount.value);
	var b,c;
	while(y > 0)
		b = Number(CheckNull(x.price[y-1].value));
		c = Number(CheckNull(x.qty[y-1].value));
		a += (b * c);
	return a;

<table border=0 align="center" cellPadding="0" cellspacing="5">
<tr><td colSpan=3><h3><b>Enter Amount</b> - $ 
	    <input name="qty" size="3" value="0">
	  <input name="price" type="hidden" value="1">
<tr><td colSpan=3><input name="price" type="hidden" value="0"></td></tr>
<tr><td><input type="hidden" name="qty" size="3" value="0"></td>

<!-- This table is used as the total calculator and postage and packaging selector. -->
<input name=card_type type=hidden value=debit_card>
<table border=0 align="center"  cellPadding="0" cellspacing="5">
<tr><td><b>Card Fee:</b></td>
	<td><input checked name="cardtype" onClick="typeOfCard(this.form,'debit_card');calculate(this.form)" type=radio value=""><B>Debit</B> (&pound;1.00)</td>
	<td><input name="cardtype" onClick="typeOfCard(this.form,'credit_card');calculate(this.form)" type=radio value=""><b>Credit</b> (3%)</td></tr>

	<!-- This line generates a button that calculates the cost of the whole order. It does not need to be altered when adding or removing products. -->
	<td colspan="2" align="right" style="text-align:center"><input name="calcButton" onClick="calculate(this.form)" type=button value="Calculate Total"></td>
	<td colspan="4" style="text-align:center"><b>Total: &pound; </b><input name="amount" size=4 value="0"></td>

<!-- This generates a button that submits the information and send the user into the Worldpay payment pages. -->
<p align="center">

<input type=submit value=Checkout onClick="calculate(this.form)"></p>