cjbeck71081 Posted October 8, 2007 Share Posted October 8, 2007 Right now i am modifying an existing code that works to use a CART_ID to query a database storing temporary information about a users Shopping Cart to populate the Shopping Cart Page. What i would like to do is add a small bit of data into the end of that URL that uses information a user fills out on a product page to pass data. Here goes: There is a Product Details Page. It has an "Add to Cart" button. It takes a piece of code called the "Cart_URL" and passes it through the button in a peice of code that looks like this: <input type="button" name="btnAddToCart" value="Add To Cart >" onclick="window.location.href='<?php echo $cart_url ?>';" /> I realise i could probably try to rewrite this code to use the "OnChange" method of Javascript to populate a PHP Variable that effectively passes the value of a drop down box called "Flavor" to the URL. I could then extract the Flavor from the URL on the Shopping Cart Page. The problem i am having is how to get Javascript to pass the value of the selected code from the drop down to a PHP variable I figured something like this: $cart_flavor = "Cherry"; (I would set the variable to the default flavor); <script> $cart_flavor = "form1.select.selected.value"; (This would change the variable of $cart_flavor to the selected value on change, if there was no selection the default value "Cherry" would stay the same) </script> <select onChange="runCode();" name="select"> <option value="Chocolate" selected="selected">TestItem1</option> <option value="Cherry">TestItem2</option> <option value="Strawberry">TestItem3</option> </select> <input type="button" name="btnAddToCart" value="Add To Cart >" onclick="window.location.href='<?php echo $cart_url $cart_flavor ?>';" /> I realise however that my syntaxt is off, but i think my methodology might work. Any suggestions would be greatly appreciated. Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/72370-javascript-form-href-with-php/ Share on other sites More sharing options...
RichardRotterdam Posted October 9, 2007 Share Posted October 9, 2007 The problem i am having is how to get Javascript to pass the value of the selected code from the drop down to a PHP variable by just reading that I believe you mean you want a javascript var to php var am i right? If this is so you can't do that directly javascript runs in your browser and php on a remote server Quote Link to comment https://forums.phpfreaks.com/topic/72370-javascript-form-href-with-php/#findComment-365065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.