Raymond Ablack
Raymond Ablack

Reputation: 9

How do I call a variable from my javascript in my php file?

I have a piece of code (JSFiddle link below), that generates a picture based on the radio button clicked. I would like to send the name of the resulting image to a form so it can be sent to a different page (payPal checkout). I can't seem to get it to work and I'm looking for help. Thanks

http://jsfiddle.net/YRWKH/

Upvotes: 0

Views: 61

Answers (2)

Mark Rawlingson
Mark Rawlingson

Reputation: 148

Use a hidden input. onclick of the radio button, set the value to the path to the image, then on post, just simply $_POST to grab the image name.

Upvotes: 0

VoteyDisciple
VoteyDisciple

Reputation: 37803

First, add a field to your form:

<input type="hidden" name="some_name" value="" id="the-hidden-field" />

Then, in your updateImage() function, you can do:

var src = "images/" + BodyColor + InsertColor + ".jpg";
$("#FinalImage").attr('src' src);
$('#the-hidden-field').val(src);

Now your hidden field has the same value as the src attribute on the image itself, and of course the hidden field will be passed to the server as would any other field.

Upvotes: 1

Related Questions