0

I want to stop users being able to choose the price they pay on the drop-down menu before paying with Paypal - the JavaScript code I have will select the price based on country chosen on the form.

However whenever I add disabled="disabled" to either the select element, or the options, this generates an error with Paypal.

Does anyone know a way around it?

<select name="os0" disabled="disabled">
<option value="Testing">Testing &#163;0.10 GBP</option>
<option value="UK">UK &#163;10.00 GBP</option>
<option value="European Union">European Union &#163;20.00 GBP</option>
<option value="Rest Of The World">Rest Of The World &#163;30.00 GBP</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="GBP">
<input type="image" id="paypalbutton" src="https://www.paypalobjects.com/en_US/i/btn/x-click-but6.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">

You can test it on http://ineedaweatherforecast.co.uk using the Buy Now button at the top.

Thanks James

  • Could it be that disabled is a Boolean attribute and is not supposed to have a value at all? It's just – Scott Marcus Mar 11 '16 at 21:47
  • Sadly that has not fixed it. – James Winfield Mar 11 '16 at 21:49
  • The issue is that once you disable an input it's not submitted with the form. You can use `readonly` instead but you'd better be checking the amount of $$$ you get back because users can still work around this. – mpen Mar 11 '16 at 21:50
  • 1
    @ScottMarcus It [doesn't matter](http://stackoverflow.com/a/4613192/65387) what value you give to a boolean attribute and in fact disabled="disabled" [is valid](http://stackoverflow.com/a/24579932/65387) – mpen Mar 11 '16 at 21:53
  • It does if you are interacting with a proprietary library that may be looking for a specific value. I've seen it before. With disabled="disabled", disabled !== true. In addition, if you get the value with jQuery, what you get will differ if you use .attr() vs. .prop() – Scott Marcus Mar 11 '16 at 21:54
  • @ScottMarcus Your library is **broken** if it doesn't interpret the attribute correctly. Also, if you use `.attr()` to read the disabled **property** in jQuery then **your code** is wrong -- `.attr` does not properly reflect the current state. – mpen Mar 11 '16 at 21:58
  • @mpen You entirely miss the point. People do make mistakes and there is no reason to code in a way that opens doors to bugs. Just because coding disabled incorrectly usually works is not justification for doing it. This is why I did not post this an an answer. It's a comment. Since I am not familiar with the PayPal API, it is a reasonable suggestion and a good best practice to follow. – Scott Marcus Mar 11 '16 at 22:00
  • Why not just `visibility: hidden;` ? – Adam Buchanan Smith Mar 11 '16 at 22:06
  • @ScottMarcus You're right, you should still code properly, but that's not the source of his problem here. – mpen Mar 11 '16 at 22:07
  • @AdamBuchananSmith A few reasons: that'll make the element disappear (which I'm guessing he doesn't want) *and* still leave a visual gap which is ugly (display:none is generally preferable) – mpen Mar 11 '16 at 22:08
  • @mpen not if there is an img as the placeholder. It would work exactly like a disabled button. – Adam Buchanan Smith Mar 11 '16 at 22:09
  • @mpen Since the OP is saying that PayPal returns an error as soon as this is added, I'd say that PayPal either disallows disabled completely or they are not happy with the value of disabled. Until the OP changes the code, you can't rule it out. – Scott Marcus Mar 11 '16 at 22:12
  • @ScottMarcus PayPal is not receiving the value **at all** because it because **it is not being submitted**. – mpen Mar 11 '16 at 22:13

1 Answers1

1

Disabled elements are not submitted with the form.

You have a few options:

  1. Use readonly instead of disabled="disabled"
  2. Leave the <select> disabled but put the real value in a <input type="hidden">
  3. Enable the element before submitting

But whatever you do, make sure you're receiving the correct amount of money because it's very easy for a user to hack around this.

mpen
  • 272,448
  • 266
  • 850
  • 1,236