Hi all,
I have a cart application in which the product page offers an item - with a <Select>dropdown next to it to select the size. Each option in the Select has a unique value. The Select itself as an ID.
When 'Add to Cart' is pressed, the first value is always sent. I realized, perhaps incorrectly, that there is no way to reference the value of the Select with PHP - to send along in the query string. So my next approach was to put in-line javascript to get the correct value in the name-value pair of the query string. Some code:
<A HRef='admin/update_cart.php?Item=" . document.forms[0].Elements['ClaryPrice . $item_count . '].value . "&redirect=sensual.php'><img src='home/cart.bmp' alt='add to cart'/></A>
I am expecting a string like this:
admin/cart?Item=45&redirect=sensual.php
The 45 is the value from the Select. Say there are three option value 45, 46, 47. A person select the third option (47) but the string also returned 45 - that was when I just used PHP.
Now I have javascript or at least DOM -- document.forms[0].Elements['ClaryPrice . $item_count . '].value
ClaryPrice3 might be the name of the Select. There are many select and the $item_count makes them unique (ClaryPrice1, ClaryPrice2, etc.)
Anyway I can't seem to get the JS/Dom reference to work right. Some possibilities:
Some of it belongs hardcoded, some of it belongs referenced (I have tried variation with no luck yet)
Perhaps inline JS can't be mixed in PHP? (although I can't see why not)
Perhaps there is a PHP way that I am not aware of to get a select's "real" value, not just its first one.
The redirect is used to return back to the page, sensual.php that the items are listed on. The update_cart.php writes the cart number and the item value to a database then redirects back to the page. And please don't get tiffed at sensual - it is a line of perfume.![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
All help appreciated!
Thanks,
KB
I have a cart application in which the product page offers an item - with a <Select>dropdown next to it to select the size. Each option in the Select has a unique value. The Select itself as an ID.
When 'Add to Cart' is pressed, the first value is always sent. I realized, perhaps incorrectly, that there is no way to reference the value of the Select with PHP - to send along in the query string. So my next approach was to put in-line javascript to get the correct value in the name-value pair of the query string. Some code:
<A HRef='admin/update_cart.php?Item=" . document.forms[0].Elements['ClaryPrice . $item_count . '].value . "&redirect=sensual.php'><img src='home/cart.bmp' alt='add to cart'/></A>
I am expecting a string like this:
admin/cart?Item=45&redirect=sensual.php
The 45 is the value from the Select. Say there are three option value 45, 46, 47. A person select the third option (47) but the string also returned 45 - that was when I just used PHP.
Now I have javascript or at least DOM -- document.forms[0].Elements['ClaryPrice . $item_count . '].value
ClaryPrice3 might be the name of the Select. There are many select and the $item_count makes them unique (ClaryPrice1, ClaryPrice2, etc.)
Anyway I can't seem to get the JS/Dom reference to work right. Some possibilities:
Some of it belongs hardcoded, some of it belongs referenced (I have tried variation with no luck yet)
Perhaps inline JS can't be mixed in PHP? (although I can't see why not)
Perhaps there is a PHP way that I am not aware of to get a select's "real" value, not just its first one.
The redirect is used to return back to the page, sensual.php that the items are listed on. The update_cart.php writes the cart number and the item value to a database then redirects back to the page. And please don't get tiffed at sensual - it is a line of perfume.
All help appreciated!
Thanks,
KB