Forum Moderators: coopster
After the user selects the size and clicks on the submit button, a new page opens and the values of color and size are passed to a new page.
How do I implement this. I am looking for a sample code that could help me out. The main problem is that if after the color is selected and I run a query, I need to reload the same page with the first drop down list retaining the value of the selected color, and the second list populated with the sizes for that color. Further on clicking the submit button, a new page is to open. How can two different actions be done on the same form ,i.e on selection from first drop down list and on click of submit button
One option might be to pre-load all the possible colour/size combinations into a JS array and use that to change the second option-list when the a colour is chosen.
;)
What I do in this situation is use javascript to initiate a form submit when the onChange event is triggered for the first select. The form action is the same page.
How can this be done? I'm not going to lay it all out for you but you can accomplish the goal by using if statements and checking for the existence of variables.
For example. Say your select box is named "color". When the page is first loaded I'd set the MySQL query for color within an if statement that checks for the existence of the var $color. If not then I'd run query and populate the first select box.
When the color is selected the var $color is set and passed to the form. SO this time $color exists and then I'd run the second query and populate the second select box.
Make sense?
Check out this PHP function:
isset [us3.php.net]
I know that I can populate the 'color' list when the page loads for the first time, and then when a color is selected, I can reload the same page and populate the 'size' list. But the problem is that once that is done, and the user has selected the color and size and then hits the submit button, how do I go to some other page, remember I have set the form action="" or form action=$PHP_SELF, coz I want the page to reload after the selection from the 'color' list.
So how will hitting the submit result in an action that takes me to a new page say buy.php
:)