Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    select OPTION not SELECTED - Am I losing my mind?

    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.

    Code:
    $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:

    Code:
    <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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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?

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Yep, the code works. Are you sure you're looking at the right code in the right place?

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    if($page == $i) $pagenumbers .= " selected";
    PHP Code:
        if($page == $i$pagenumbers .=  ' selected="selected"'
    </nitpicking>

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks guys. I output it simply with:

    Code:
    echo "<div id='pg'>\n";
    echo $pagenumbers;
    echo "</div>\n";
    I swear I'm not crazy!

  • #6
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tried that too.

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


    Quote Originally Posted by aedrin View Post
    PHP Code:
        if($page == $i$pagenumbers .=  ' selected="selected"'
    </nitpicking>

  • #7
    New Coder
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •