I’m using the basic PayPal shopping cart (Website Payments Standard).
I have the following in my HTML as part of an item description:
<div class="block">
<p>What’s yours?</p>
<!-- some other html -->
</div>
I then select this piece of text like this:
phrase = $('.block p:first').text();
I have also tried this:
phrase = $('.block p:first').html();
Then, before it’s submitted, I copy it into the form like this:
$('#PayPalForm input[name=os1]').val(phrase);
The form looks like this:
<form id="PayPalForm" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="business" value="redacted" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="return" value="paypal_confirm.html" />
<input type="hidden" name="cancel_return" value="redacted" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="bn" value="PP-ShopCartBF" />
<input type="hidden" name="item_name" value="" />
<input type="hidden" name="on1" value="phrase" />
<input type="hidden" name="os1" id="os1" value="" />
</form>
This is my HTML doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
This is my text encoding:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
It’s working. However, when the remotely hosted cart page opens (at PayPal), the phrase is displayed with non-sensical characters where an apostrophe should be.
phrase: What’s yours?
At the very least I would have expected the raw ’ to display rather than a ’.
Why did this happen and what can I do to clean it up?
You should be able to specify the encoding of the information contained in your form: Setting the Character Set – charset.