![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Help in selected drop-down list doesn't show
Hi. Please help with my code. I have a drop down list selected using an array to select the month and year for expiration date. The problem is, when I select the month and year and some fields has error, the page refresh but the selection I made for the month is gone and it goes back to the default which is the first selected Index as "--". Below is my array as it is written:
PHP Code:
PHP Code:
|
|
|
|
|
|
PM User | #2 |
|
New Coder ![]() Join Date: Dec 2007
Posts: 88
Thanks: 0
Thanked 3 Times in 3 Posts
![]() |
Have you thought of using sessions to store the selected values. So that next time when the page refreshes the values from session are checked for the drop down box.
Also while refreshing are you doing post back to the server? in that case you may read the drop down values selected prior to refreshing the page and check these values against the values in drop down.
__________________
Programming & Webmaster Forum - Win $5 every week on technicaltalk.net for answering solutions Forum Post Exchange Resource Forum |
|
|
|
|
|
PM User | #3 | |
|
Master Coder ![]() Join Date: Mar 2007
Location: God's own country
Posts: 8,976
Thanks: 142
Thanked 1,192 Times in 1,184 Posts
![]() ![]() ![]() ![]() |
Write an if condition to check the value in th posted data against the value from your foreach loop and add an attribute like
selected="selected" for the matched one..
__________________
Quote:
|
|
|
|
|
|
|
PM User | #4 | |
|
New Coder ![]() Join Date: Oct 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Quote:
|
|
|
|
|
|
|
PM User | #5 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Hi abduraooft, thanks for your suggestion. I actually use the if condition and use
Code:
selected="selected" |
|
|
|
|
|
PM User | #6 | |
|
Master Coder ![]() Join Date: Mar 2007
Location: God's own country
Posts: 8,976
Thanks: 142
Thanked 1,192 Times in 1,184 Posts
![]() ![]() ![]() ![]() |
That attribute has to be applied on the required <option> tag and not on the <select> tag
__________________
Quote:
|
|
|
|
|
|
|
PM User | #7 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Thanks a lot for your help abduraooft but it really doesn't work. I tried to include the
Code:
selected="selected" Code:
[option][/option] |
|
|
|
|
|
PM User | #8 |
|
New Coder ![]() Join Date: Oct 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Is there any other way to do it instead of using PHP? I guess it is better if I use regular HMTL but it will be long, can somebody please advice? I need to make this work by tomorrow and I am really behind as I am spending lots of time just to make this problem work. Please help!!!!! Thanks.
|
|
|
|
|
|
PM User | #9 |
|
Regular Coder ![]() Join Date: Apr 2005
Posts: 100
Thanks: 0
Thanked 31 Times in 31 Posts
![]() |
PHP Code:
Please try: PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|