How can I pass variables from JavaScript to PHP?

Generally speaking, you shouldn’t return the selected price to the server. HTML forms can be easily faked. It is far safer to send the user’s choice back to the server, which also knows how much it should cost.

Basically Javascript validation (which this essentially is) is convenient but shouldn’t be trusted. You already have an input for selecting the finish. Just send that back to the server. That way your site will still work (or work better) if the user has Javascript disabled.

Leave a Comment