jQuery to change value on submit

I have a problem by using a PayPal donation-button.

The currency format for PayPal is defined with a dot. In europe Our currency uses comma. This causes a problem where after submitting the form PayPal says that there is a wrong format for the amount.

Usually it would not be an issue to simply use str_replace(',','.', $_POST['amount']) but the form will be send directly to PayPal so that there is no chance to validate/replace the input by using php.

That is why I need to use jQuery.

The basic idea is to check if there is a comma in the value and in case just replace the comma with a dot and return true to post the form.

$(function() {
    $('#paypal').submit(function() {
           if ($('#amount') contains a comma) {
              replace comma with dot;
           }
      }
        return true; 
    });
});

I usually don’t use jQuery. So if there is some who could help me out I really would appreciate.

Thanks in advance.


Source: jquery

Leave a Reply