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 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.