Jump to content

drop down grey and non selectable option


kvnirvana

Recommended Posts

How can i make the ‘all’ selection in the drop down list to be non selectable and greyed out but still shown as the first option when the user opens the page with the dropdowns?

 

 

 

/*------------------------------------------------------------------------ 
            create the drop downs 
------------------------------------------------------------------------*/ 

function dropdown($field, $table) 
{  
  //initialize variables 
  $oHTML  = ''; 
  $result = ''; 
  
  //check to see if the field is passed correctly 
  if (($field == "")||($table == "")) 
  { 
    die("No column or table specified to create drop down from!"); 
  } 

  $sql = "select distinct($field) from $table"; 
  
  //call the db function and run the query 
  $result = conn($sql); 

  //if no results are found to create a drop down return a textbox 
  if ((!$result) ||(mysql_num_rows($result)==0)) 
  { 
    $oHTML .= "<input type='text' name='$field' value='' size='15'>"; 
  }elseif (($result)&&(mysql_num_rows($result)>0)){ 
    
    //build the select box out of the results 
    $oHTML .= "<select name='$field'>\n<option value='all'>All</option>\n"; 
    while ($rows = mysql_fetch_array($result)) 
    { 
      $oHTML .= "<option value='".$rows[$field]."'>".$rows[$field]."</option>\n"; 
    } 
    $oHTML .= "</select>\n"; 
  } 
  
  //send the value back to the calling code 
  return $oHTML; 
}//end function 

 

 

 

You can disable the whole select element, but you cannot disable a single option.

 

The best you can do is add the option, then have a check in the background that sends back an error if the user selects that option. There is no way to prevent an option from being selected though.

Sorry about that, i just skimmed over your question. Haku is correct that you cannot disable a single element.

 

I would just give the option a value of zero, or ''. Then, I'd firstly make sure that the value>0 or value!='' when the user is submitting to form, via javascript, and secondly make the same check in php, since a user can disable javascript, and get by your validation.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.