Paypal donation button with minimum amount

If you would like to allow a buyer to enter an amount to pay for your downloadable product like a donation and force a minimum payment you can use the following.

1) In the HEAD section of your page paste in the following javascript code.

<script type="text/javascript">
<!--
function mindonation(form,minprice)
{
  var price=form.amount.value;
  price=price.trim();
  price=price.replace(",",".");
  if ((isNaN(parseFloat(price))) || (!isFinite(price)))
  {
    alert ( "Please enter a valid amount of at least "+minprice);
    form.amount.focus();
    return(false);
  }
  if (price<minprice)
  {
    alert ( "Please enter a minimum donation of "+minprice);
    form.amount.focus();
    return(false);
  }
  price=Number(price);
  var currency=form.currency_code.value;
  if ((currency=="JPY") || (currency=="HUF") || (currency=="TWD"))
   form.amount.value=price.toFixed(0);
  else  
   form.amount.value=price.toFixed(2);
  return(true);
}
//-->
</script>

2) Change the type attribute of the amount field in your Paypal button from hidden to text. So for example change

<input type"'hidden" name="amount" value="">
to be
<input type"'text" name="amount" value="">

If you wish you can set value to a suggested amount such as value="10.00". This amount would be used if javascript is disabled as well.

3) In the form tag add onSubmit="return mindonation(this,5.99)" changing the 5.99 to the minimum donation like this

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="return mindonation(this,5.99)">
4) In linklokipn.php make sure the price set for the product is the minimum donation amount.
Here is an example complete button that can be used. You need to set your business, item_number, item_name and currency_code as needed.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onSubmit="return mindonation(this,5.99)">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paypal@yoursite.com">
<input type="hidden" name="item_name" value="Product Description">
<input type="hidden" name="item_number" value="id1">
<input type="hidden" name="currency_code" value="USD">
<input type"'text" name="amount" value="">
<input type="submit" name="submit" value="Donate and download">
</form>