| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Retaining selected Item in dropdown menu | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Retaining selected Item in dropdown menu
I have a template I've written that is visible above the categories in the left menu. The template has a series of dropdown boxes. When a year is selected from the first the onchange event fires a query to fill the second combo box and the page reloads. What happens is that the value of the year is not remaining in the first box. The second box is populated, but the first box still says "Select Year". I just tried adding the {if} statement to the first dropdown, but no luck. I have also tried adding a series of selection lines that look like:
<option value="2009" {php} if (!(strcmp(2009, $year))){echo "selected";}{/php}>2009</option> Without any success. How do I get the selected year to stick when the page reloads? Here is the tpl code: Code:
__________________
Adam X-Cart Gold 4.4.5 - Live X-Cart Gold 4.1.11 - Retired X-Payments 1.0.4 CDSEO Pro EWD Hosting Last edited by AMMoyer : 01-08-2009 at 11:56 AM. Reason: adding code tags |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Retaining selected Item in dropdown menu
HTML Code:
HTML Code:
Also it may be caused by duplicating options with the same value F.e. if 2009 is selected you will get HTML Code:
__________________
Regards, Victor Dubiniuk X-Cart Skins Store - twenty two different skins for 4.1.x and 4.2.x; - 4.3.x compatible versions are available; - refresh you store now! Smart menu X-Cart add-on for 4.1.8 - 4.3.x Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x |
|||||||||
#3
|
|||||||
|
|||||||
Re: Retaining selected Item in dropdown menu
My first attempt was without the {if} statements in the dropdown select lines and it won't retain the value after its picked. Is this because its loading a new page when the year is picked and the form is reset?
I have not tried the {foreach} or {section} method yet. I have tried the Smarty html_options statement that is commented out below the "hardcoded" select I'm working on now. It is filled from a db query in the php file and will not fill the combo box until I go to that php file in the browser, while the hardcoded way, and probably the {foreach} and {section} way load whenever the template is called. What is the most correct way to get the Year to stick after there has been a value selected? Ideally I'd like it to remain whenever that template is called. Thanks.
__________________
Adam X-Cart Gold 4.4.5 - Live X-Cart Gold 4.1.11 - Retired X-Payments 1.0.4 CDSEO Pro EWD Hosting |
|||||||
#4
|
|||||||||
|
|||||||||
Re: Retaining selected Item in dropdown menu
Don't you forget to pass this variable to smarty in php code?
Something like this: Code:
__________________
Regards, Victor Dubiniuk X-Cart Skins Store - twenty two different skins for 4.1.x and 4.2.x; - 4.3.x compatible versions are available; - refresh you store now! Smart menu X-Cart add-on for 4.1.8 - 4.3.x Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x |
|||||||||
#5
|
|||||||
|
|||||||
Re: Retaining selected Item in dropdown menu
Here is my php file I probably should have posted initially. I do post the variable as "yearid" and maybe that is my issue.
Code:
__________________
Adam X-Cart Gold 4.4.5 - Live X-Cart Gold 4.1.11 - Retired X-Payments 1.0.4 CDSEO Pro EWD Hosting |
|||||||
#6
|
|||||||||
|
|||||||||
Re: Retaining selected Item in dropdown menu
Yes
$smarty->assign("yearid", $yearid); should be $smarty->assign("year", $yearid); Also all the variables that came with POST are accesible directly: Code:
The first line is excessible - top.inc.php do this job for you
__________________
Regards, Victor Dubiniuk X-Cart Skins Store - twenty two different skins for 4.1.x and 4.2.x; - 4.3.x compatible versions are available; - refresh you store now! Smart menu X-Cart add-on for 4.1.8 - 4.3.x Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x |
|||||||||
#7
|
|||||||
|
|||||||
Re: Retaining selected Item in dropdown menu
Thank you Victor D!! I changed
$smarty->assign("yearid", $yearid); to $smarty->assign("year", $yearid); but this does not help with the code below. Now here is my tpl file that I'm trying to work with the {foreach} statement and it only shows "Array" for all choices in the combo box. I am obviously missing something. Code:
__________________
Adam X-Cart Gold 4.4.5 - Live X-Cart Gold 4.1.11 - Retired X-Payments 1.0.4 CDSEO Pro EWD Hosting |
|||||||
#8
|
|||||||||
|
|||||||||
Re: Retaining selected Item in dropdown menu
Ooops.
Quote:
so $smarty->assign("year", $year); should work
__________________
Regards, Victor Dubiniuk X-Cart Skins Store - twenty two different skins for 4.1.x and 4.2.x; - 4.3.x compatible versions are available; - refresh you store now! Smart menu X-Cart add-on for 4.1.8 - 4.3.x Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x |
|||||||||
#9
|
|||||||
|
|||||||
Re: Retaining selected Item in dropdown menu
Thank you Victor!!!
One last question on this subject. The years are working great and then the Makes are loading properly, but I am having trouble getting the Make to "stick" in the dropdown box also. I'm sure there is something mis-named or there's an issue with the {if} statement, but I've been staring at it too long to find it. Thanks again. Partial TPL code: Code:
Partial PHP code: Code:
__________________
Adam X-Cart Gold 4.4.5 - Live X-Cart Gold 4.1.11 - Retired X-Payments 1.0.4 CDSEO Pro EWD Hosting |
|||||||
#10
|
|||||||||
|
|||||||||
Re: Retaining selected Item in dropdown menu
You didn't pass the active make to template once again.
The code you have posted is not enough so I used sources posted above insert below the line $smarty->assign("makes", $makes); this one Code:
and in tpl: Code:
I used to take the sheet of paper and make a draft when something is unclear.
__________________
Regards, Victor Dubiniuk X-Cart Skins Store - twenty two different skins for 4.1.x and 4.2.x; - 4.3.x compatible versions are available; - refresh you store now! Smart menu X-Cart add-on for 4.1.8 - 4.3.x Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x |
|||||||||
|
|||
X-Cart forums © 2001-2020
|