...

View Full Version : select OPTION not SELECTED - Am I losing my mind?



fishnyc22
11-08-2007, 08:03 PM
Ok. I'm either going crazy or I've just been plain sitting here to long.

I have this simple loop to build a select field showing page numbers. But for some weird reason. its compeltely ignoring the SELECTED copy that should be written into the option field.



$page = (!isset($_GET['page'])) ? 1 : $_GET['page'];
$pagenumbers = "";
$pagenumbers .= " <form><select name='menu1' onchange=\"MM_jumpMenu('parent',this,0)\">\n";


for($i = 1; $i <= $total_pages; $i++) {
$pagenumbers .= " <option value='" . $_SERVER['PHP_SELF'] . "?a=" . $ashort. "&page=" . $i . "'";
if($page == $i) $pagenumbers .= " selected";
$pagenumbers .= ">Page $i</option>\n";
}

$pagenumbers .= " </select></form>\n";



I've checked al values for $page, and $i, ran and echo test to see what its doing and still nothing. When I view the source on the page I see:



<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
<option value="index.php?a=test&amp;page=1">Page 1</option>
<option value="index.php?a=test&amp;page=2">Page 2</option>
<option value="index.php?a=test&amp;page=3">Page 3</option>
<option value="/index.php?a=test&amp;page=4">Page 4</option>
</select>


Am I going nuts. why would it not write in the selected. there is definately a match when it sees 'page' number in the URL string.

Whats weird is that its writing "&amp;" and it also converted my single quotes to double (but maybe thats normal)....

Please bail me out of this ridiculous hole I'm in :)

Fumigator
11-08-2007, 08:20 PM
I tried your exact code (with an added echo $pagenumber; at the bottom) and it worked just as you'd expect. So yes, you are going crazy.

How is $pagenumber getting outputted?

Inigoesdr
11-08-2007, 08:31 PM
Yep, the code works. Are you sure you're looking at the right code in the right place?

aedrin
11-08-2007, 08:48 PM
if($page == $i) $pagenumbers .= " selected";


if($page == $i) $pagenumbers .= ' selected="selected"';

</nitpicking>

fishnyc22
11-08-2007, 08:52 PM
thanks guys. I output it simply with:



echo "<div id='pg'>\n";
echo $pagenumbers;
echo "</div>\n";


I swear I'm not crazy!

fishnyc22
11-08-2007, 08:53 PM
tried that too.

I even tried to just hard code "selected" into the area and it isnt showing up.




if($page == $i) $pagenumbers .= ' selected="selected"';

</nitpicking>

fishnyc22
11-08-2007, 10:42 PM
OK. I think whats going on is related to the "&amp;" in the URLs. What would cause them to not be converted to &?

Could it be an HTML error that I'm not seeing?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum