-
June 12th, 2010, 08:18 AM
#1
Wanto to keep drop down value selected after submit
I have a webshop. I have a little problem in the admin side.
There's a text field what is written in the sql database after pressing submit. Also there's drop down menu where I have to select product category where I information should be send. At this moment drop down menu has 1156 categories.
Let's say I want to export information to the category 890. I search category 890 in the list and press submit. Now page will be refreshed and now drop down menu doesn't remember what I selected before. Again I have to open drop down menu and search next category 891 and submit staff there. Now page will be refreshed and now drop down menu has again default value which is "Select". And again again again I have to scroll down to find 892.
I want that list remembers it's value after submit is pressed.
You know what I mean?
List of the menu is generated like this:
PHP Code:
<?php
$result = mysql_query ("SELECT * FROM $clover_shop_categories WHERE cs_category_title IS NOT NULL ORDER BY cs_category_listing_position asc");
if (mysql_num_rows ($result)) {
echo "<SELECT name=\"import_category\">\n";
echo "<OPTION value=\"\">- choose category -</OPTION>\n";
echo "<OPTION value=\"\"></OPTION>\n";
while ($s = mysql_fetch_array ($result)) {
echo "<OPTION value=\"$s[cs_category_id]\">";
for ($i = 2; $i <= $s['cs_category_level']; $i++) echo " ";
echo "$s[cs_category_title]</OPTION>\n";
}
echo "</SELECT>\n";
}
?>
That code is not written by me. It's a direct copy of the webshop of the importing tool.
What I should do? Remember also that I don't know much about php...
-
June 12th, 2010, 07:17 PM
#2
Re: Wanto to keep drop down value selected after submit
Compare the <option> tag value with the submitted value. If they match, echo [i]selected="selected[/b] in the tag.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 13th, 2010, 03:01 AM
#3
Re: Wanto to keep drop down value selected after submit
Ok.... but what I should write?
-
June 13th, 2010, 11:52 AM
#4
Re: Wanto to keep drop down value selected after submit
PHP Code:
$selected = ($s['cs_category_id'] == $_POST['import_category']) ? "selected=\"selected\"" : ""; echo "<OPTION value=\"$s['cs_category_id']\"$selected>";
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 13th, 2010, 03:00 PM
#5
Re: Wanto to keep drop down value selected after submit
PHP Code:
<?php
$result = mysql_query ("SELECT * FROM $clover_shop_categories WHERE cs_category_title IS NOT NULL ORDER BY cs_category_listing_position asc");
if (mysql_num_rows ($result)) {
echo "<SELECT name=\"import_category\">\n";
echo "<OPTION value=\"\">- choose category -</OPTION>\n"; echo "<OPTION value=\"\"></OPTION>\n";
$selected = ($s['cs_category_id'] == $_POST['import_category']) ? "selected=\"selected\"" : ""; echo "<OPTION value=\"$s['cs_category_id']\"$selected>";
while ($s = mysql_fetch_array ($result)) {
echo "<OPTION value=\"$s[cs_category_id]\">"; for ($i = 2; $i <= $s['cs_category_level']; $i++) echo " "; echo "$s[cs_category_title]</OPTION>\n";
}
echo "</SELECT>\n"; } ?>
Like that? I suppose no because blank screen is result.
Last edited by Temporary-Failure; June 13th, 2010 at 03:03 PM.
-
June 13th, 2010, 09:40 PM
#6
Re: Wanto to keep drop down value selected after submit
No. The two line I supplied should replace the one two lines down. Notice the echo option similarities?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 14th, 2010, 01:08 AM
#7
Re: Wanto to keep drop down value selected after submit
PHP Code:
<?php
$result = mysql_query ("SELECT * FROM $clover_shop_categories WHERE cs_category_title IS NOT NULL ORDER BY cs_category_listing_position asc");
if (mysql_num_rows ($result)) {
echo "<SELECT name=\"import_category\">\n";
echo "<OPTION value=\"\">- choose category -</OPTION>\n"; echo "<OPTION value=\"\"></OPTION>\n";
while ($s = mysql_fetch_array ($result)) {
$selected = ($s['cs_category_id'] == $_POST['import_category']) ? "selected=\"selected\"" : ""; echo "<OPTION value=\"$s['cs_category_id']\"$selected>"; for ($i = 2; $i <= $s['cs_category_level']; $i++) echo " "; echo "$s[cs_category_title]</OPTION>\n";
}
echo "</SELECT>\n"; } ?>
Like this?
Result is a blank screen.
Last edited by Temporary-Failure; June 14th, 2010 at 01:13 AM.
-
June 14th, 2010, 07:11 AM
#8
Re: Wanto to keep drop down value selected after submit
Two possibilities.
1. The original code doesn't have the single quotes around cs_category_I'd. Try removing them from both lines.
2. Since you didn't post the form, I just guessed that it used POST and not GET.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
June 14th, 2010, 08:17 AM
#9
Re: Wanto to keep drop down value selected after submit
Originally Posted by PeejAvery
Two possibilities.
1. The original code doesn't have the single quotes around cs_category_I'd. Try removing them from both lines.
2. Since you didn't post the form, I just guessed that it used POST and not GET.
YOUR'E THE MAN!!!
I removed single quotes of
echo "<OPTION value=\"$s['cs_category_id']\"$selected>";
and it worked perfectly!!! Thank you so very much. If you some day come here in Finland I will offer you a beer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|