View Full Version : Remember the results selected on the list
michelle
09-18-2002, 04:27 AM
Hi, I knew this had been asked by someone. But I can't find post which are the same as mine. Ok, the thing is, I 've a select menu which let user choose the number of records to be shown. I'm using asp tags. By default it select 40. So if the user select 10, the page reloads but the menu jumps back to 40. How can I specify it to stay? By the way, this select menu was on my html template.
<select name="menu1" onChange="MM_jumpMenu('self',this,0)">
<option value="browse.php?cat=<%cat%>&size=10">10 Results</option>
<option value="browse.php?cat=<%cat%>&size=20">20 Results</option>
<option value="browse.php?cat=<%cat%>&size=30">30 Results</option>
<option value="browse.php?cat=<%cat%>&size=40" selected>40 Results</option>
<option value="browse.php?cat=<%cat%>&size=50">50 Results</option>
</select>
Any idea how I could pass the value?
Spookster
09-18-2002, 04:34 AM
Assuming you are storing the size as a variable then:
<select name="menu1" onChange="MM_jumpMenu('self',this,0)">
<option value="browse.php?cat=<%cat%>&size=10" <% if($size=="10") echo "selected" %>>10 Results</option>
<option value="browse.php?cat=<%cat%>&size=20" <% if($size=="20") echo "selected" %>>20 Results</option>
<option value="browse.php?cat=<%cat%>&size=30" <% if($size=="30") echo "selected" %>>30 Results</option>
<option value="browse.php?cat=<%cat%>&size=40" <% if($size=="40") echo "selected" %>>40 Results</option>
<option value="browse.php?cat=<%cat%>&size=50" <% if($size=="50") echo "selected" %>>50 Results</option>
</select>
michelle
09-18-2002, 04:58 AM
hi spookster, it don't seems to work. Also an ">" was added. By the way, I choose to use dynamic instead. But I wanted a record of 10, 20, 30, 40, 50....and so on till 100, but this loop only show 100 on the list. Any idea why?
for($records = 10; $records <= 100; $records += 10) {
$record = "<select name=menu1 onChange=\"MM_jumpMenu('self',this,0)\">\n";
$record .= "<option value=\"browse.php?cat=<%cat%>&size=10\">" . $records . " Results</option>\n";
$record .= "</select>\n";
}
mordred
09-18-2002, 02:50 PM
That's because you always reset the $record string on each loop iteration, insead of concatenating the new contents with .= operator.
But I have a slight notion that you rather wanted something like this... ;)
$record = "<select name=menu1 onChange=\"MM_jumpMenu('self',this,0)\">\n";
for ($records = 10; $records <= 100; $records += 10) {
$record .= "<option value=\"browse.php?cat=<%cat%>&size=10\">" . $records . " Results</option>\n";
}
$record .= "</select>\n";
echo $record;
mordred
09-18-2002, 02:56 PM
Oh, and if you want the chosen record number to be preselected in the list, do
$record = "<select name=menu1 onChange=\"MM_jumpMenu('self',this,0)\">\n";
if (isset($_GET['size'])) {
$chosenSize = $_GET['size'];
}
for ($records = 10; $records <= 100; $records += 10) {
$record .= "<option value=\"browse.php?cat=<%cat%";
if ($records == $chosenSize) {
$record .= " selected";
}
$record .= ">&size=10\">" . $records . " Results</option>\n";
}
$record .= "</select>\n";
echo $record;
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.