SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    disabled select drop down displays more than one line

    Hello all,

    The following code disables the select but it continues to show more than one line in the drop down. The condition should only display one disabled line.

    Can someone tell me why?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    
    <?php
    
    echo "<br /><br /><br /><br />";
    
    function selected($opt1,$opt2) {
        if ($opt1 === $opt2) echo 'selected="selected"';
    }
    
    function disabled($opt1,$opt2) {
        if ($opt1 === $opt2) echo 'disabled="disabled"';
    }
    
    $candidacy4 = "4";
    
    echo '<select id="candidacy4" name="candidacy4">'."  \n";
    if ($candidacy4 != "4") { ?>
        <option <?php selected($candidacy4,"4");?> value="4">Accepted</option>
        <option <?php selected($candidacy4,"0");?> value="0">Not Accepted</option>
    <?php } else { ?>
        <option <?php disabled($candidacy4,"4");?> >Accepted</option>
    <?php 
        } // end if
    echo "  \n";
    echo '</select>&nbsp; why is this doing this?'."  \n";
    
    ?>
    
    </body>
    </html>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Where in the script do you first assign a value to $candidacy4 because in the code you have there it never gets assigned a value.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    $candidacy4 = "4"; is in his code with double quotes and the if has double quotes.

    The script is working because you are asking if $candidacy4 does not equal 4 to display the selection or else if it is equal to 4 display accepted (disabled).

    What is it that you want it to do?
    What I lack in acuracy I make up for in misteaks

  4. #4
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the w3school site, the normal output shows one select line greyed out.
    http://www.w3schools.com/TAGS/tryit....elect_disabled

    In my routine, with the variable = 4, the pulldown shows a blank line followed by a greyed out line.

    My code is an except. I am getting the variable from a table and if the variable is equal to a condition "4" then it should only provide the one select line disabled.

    Does anyone see something in my code that allows it to show more than one line when = 4?

  5. #5
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by peterb View Post
    At the w3school site, the normal output shows one select line greyed out.
    When I ran your code I got
    Code:
    <select id="candidacy4" name="candidacy4">  
    <option disabled="disabled" >Accepted</option>
    </select>
    Only one option that is disabled.
    What I lack in acuracy I make up for in misteaks

  6. #6
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew I should have mentioned the browser!

    I usually do my testing using FF but after your post, I checked using IE and it shows it differently.

    Any ideas as to how to correct this for FF?

  7. #7
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you show your HTML code?
    How can we help without seeing it?

  8. #8
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I ran the script and it had problems in ff. viewed the source and made a new file with just the html source and it worked fine.

    This doesn't make sense.
    What I lack in acuracy I make up for in misteaks

  9. #9
    SitePoint Addict peterb's Avatar
    Join Date
    Jun 2003
    Location
    Athens, Greece
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did a search on the net and found some references to this problem but they were years ago when the browsers were older.

    I will try creating a new file using the same code, thanks.


Bookmarks

Posting Permissions

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