1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Does anybody know how to make drop down boxes stay selected after doing a search?

    I have a keyword search set up on my regional search engine. The search function not only uses keywords to search, it also uses 2 drop down boxes. vFor instance let's say you were looking for "Cheap" "real estate" in "Fort Collins." First, you would click the category drop down menu "Real Estate," then you would click the city drop down menu "Fort Collins" and finally enter the keyword "Cheap" into the search field.

    The search results page works fine, however it would cool if the drop down boxes stayed selected (i.e. Real Estate, Fort Collins, and not to push it, but it would be really cool if the keywords stayed in the search field too).

    You can see it in action if you go here: http://johnny.ncolorado.com/youwontguess.php3.

    Here's the code:

    $sql = " SELECT * FROM cities ORDER BY city";
    $city_result = mysql("nco", $sql);
    $city_num = mysql_numrows($city_result);

    $sql = " SELECT categories.*, categoryparent.category_id";
    $sql .= " FROM categories,categoryparent";
    $sql .= " WHERE categories.category_id=categoryparent.category_id";
    $sql .= " && categoryparent.parent_id=0";
    $sql .= " ORDER BY category";
    $categories_result = mysql("nco", $sql);
    $categories_num = mysql_numrows($categories_result);
    $catpercolumn = round($categories_num / 2);

    <FORM ACTION="nc_results.php3" ENCTYPE="x-www-form-encoded" METHOD="POST">
    <TD ALIGN=RIGHT WIDTH="15"><IMG SRC="images/ncsearchleftround.gif" HEIGHT=55 WIDTH=13></TD>
    <TD WIDTH="570" BGCOLOR="#CC9900">
    <TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>&nbsp;
    Choose A City</FONT></FONT></FONT></B></TD>

    <TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>Pick
    A Category</FONT></FONT></FONT></B></TD>

    <TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>Enter

    <TD><IMG SRC="images/dell2.gif" HEIGHT=13 WIDTH=101></TD>


    <!--Start City Drop Down List-->
    <TD>&nbsp;<SELECT name = "city_id"><OPTION value="all">All Cities
    <? $i = 0; while ($i < $city_num) { ?>
    <OPTION value="<? echo mysql_result($city_result, $i, "city_id"); ?>"><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($city_result, $i, "city"); ?>
    <? $i++; } ?>
    <!--End City Drop Down List-->

    <!--Start Category Drop Down List-->
    <TD><SELECT name="category_id"><OPTION value="all">All Categories
    <? $i = 0; while ($i < $categories_num) { ?>
    <OPTION value="<? echo mysql_result($categories_result, $i, "category_id"); ?>"><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($categories_result, $i, "category"); ?>
    <? $i++; } ?>
    <!--End Category Drop Down List-->

    <TD><INPUT type="text" Name="keywordsearch" size="22">

    <TD>&nbsp;<INPUT TYPE="submit" NAME="submit" VALUE="Search"></TD>

    <TD ALIGN=LEFT WIDTH="15"><IMG SRC="images/ncsearchrightround.gif" HEIGHT=55 WIDTH=13></TD>


    <TD><FONT FACE="Arial,Helvetica"><FONT SIZE=-1><A HREF="about.php3">What
    Is This?</A> |&nbsp;</FONT> <FONT SIZE=-1><A HREF="addsite.php3">Add Your
    Site</A></FONT></FONT> |&nbsp;<FONT FACE="Arial,Helvetica"><FONT SIZE=-1>
    <A HREF="feedback.php3">Feedback</A> | <A HREF="faq.php3">Frequently Asked
    Questions</A> | <A HREF="faq.php3">Help</A> | <A HREF="searchtips.php3">Search

  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    In your case I would use javascript to navigate and to pass the option-value as variable attached to the URL to a reload of the menu and set the selected option.
    E.g. <FORM onSubmit="changePages(this.form)">; in your javascript function you then define:
    changePages(form) {
    parent.frame1name.location.href = nc_results.php3; parent.frame2name.location.href = menu.php3?city_id=form.select1name.options[form.select1name.selectedIndex].value&category_id=form.select2name.options[form.select2name.selec tedIndex].value;
    In your menu.php3 file you script:
    <? $i=0; while (....): ?>
    if($row["city_id"]== $city_id) { $selected=" SELECTED"; }
    else {$selected = ""; }
    <OPTION value="<? echo mysql_result($city_result, $i, "city_id"); ?>"<? echo $selected; ?>><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($city_result, $i, "city"); ?>
    <? $i++; endwhile ?>

    Do the same for category_id.

    Hope it gets you where you want to go!

    [This message has been edited by PAV (edited 12-14-99).]

    [This message has been edited by PAV (edited 12-14-99).]

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 10:32 AM
  2. Replies: 4
    Last Post: February 14th, 2005, 12:58 AM
  3. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 08:43 PM
  4. Is there any alternative to fulltext search?
    By irishairpics in forum MySQL Help
    Replies: 2
    Last Post: December 10th, 2003, 03:40 PM
  5. Site html search with php?
    By stojan in forum PHP Development
    Replies: 1
    Last Post: November 17th, 2003, 10:20 PM

IMN logo majestic logo threadwatch logo seochat tools logo