Shamrox Posted January 28, 2008 Share Posted January 28, 2008 I have a select form field (dropdown) that lists values that are enumerated in my database table. I now don't want one of the values to be selectable, but if an old record is selected for viewing and it has this value already saved, i'd like it to show in the dropdown. I just don't want any new records to be able to be given this value. Possible? If so, how would I adjust my current code shown below? Thanks. <select name=registrationstatus size=1 onChange="setChangedIndicator('hide');" > <option value='Unknown'<?PHP echo (@$regstatus == "Unknown")?" selected=\"selected\"":""; ?>>Unknown</option> <option value='Quote'<?PHP echo (@$regstatus == "Quote")?" selected=\"selected\"":""; ?>>Quote</option> <option value='Enrolled'<?PHP echo (@$regstatus == "Enrolled")?" selected=\"selected\"":""; ?>>Enrolled</option> <option value='Pending'<?PHP echo (@$regstatus == "Pending")?" selected=\"selected\"":""; ?>>Pending</option> <option value='Cancelled Student'<?PHP echo (@$regstatus == "Cancelled Student")?" selected=\"selected\"":""; ?>>Cancelled Student</option> <option value='Cancelled Vendor'<?PHP echo (@$regstatus == "Cancelled Vendor")?" selected=\"selected\"":""; ?>>Cancelled Vendor</option> <option value='Rescheduled'<?PHP echo (@$regstatus == "Rescheduled")?" selected=\"selected\"":""; ?>>Rescheduled </select> Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/ Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 It's much easier to put the options in an array and loop through them.... $options = array( 'Unknown', 'Quote', 'Enrolled', 'Pending', 'Cancelled Student', 'Cancelled Vendor', 'Rescheduled' ); $html = ' <select name=registrationstatus size=1 onChange="setChangedIndicator(\'hide\');" >'; foreach ($options as $value) { $html .= ' <option value="' . $value . '" ' . ($value == $regstatus ? 'selected="selected"' : '') . '>' . $value . '</option>'; if (!in_array($regstatus, $options)) { $html .= ' <option value="' . $regstatus . '" selected="selected">' . $regstatus . '</option>'; } } $html .= ' </select>'; Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-451452 Share on other sites More sharing options...
Shamrox Posted January 28, 2008 Author Share Posted January 28, 2008 Not really sure how that answered my question. Btw, the value I don't want selectable is "Rescheduled" Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-451453 Share on other sites More sharing options...
Shamrox Posted January 28, 2008 Author Share Posted January 28, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-451610 Share on other sites More sharing options...
KrisNz Posted January 28, 2008 Share Posted January 28, 2008 You just need a condition that checks whether the record is 'old' or not and output accordingly... <?php if ($record == 'old') : ?> <option value='Rescheduled'<?PHP echo (@$regstatus == "Rescheduled")?" selected=\"selected\"":""; ?>>Rescheduled <?php endif; ?> There's a disabled attribute for the option tag, but IE doesn't seem to support it. If you wanted to show it without it being selectable, I think you'd need to search for a javascript solution. Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-451637 Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 if (!in_array($regstatus, $options)) { $html .= ' <option value="' . $regstatus . '" selected="selected">' . $regstatus . '</option>'; } If the value isn't in the array that contains the current values, then it specifically adds that one to the drop down using the above if statement...hence the use of an array...it makes checking to see if it exists easier. Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-451651 Share on other sites More sharing options...
Shamrox Posted January 29, 2008 Author Share Posted January 29, 2008 So, if I understand correctly, if I remove the word Rescheduled from the array list in your above code, it won't show in the dropdown list, but if it's in the database record and that is loaded, it will show? Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-452503 Share on other sites More sharing options...
hitman6003 Posted January 29, 2008 Share Posted January 29, 2008 yes Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-452638 Share on other sites More sharing options...
Shamrox Posted January 29, 2008 Author Share Posted January 29, 2008 Great, thanks for the assist. Quote Link to comment https://forums.phpfreaks.com/topic/88222-solved-enum-dropdown-values/#findComment-452645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.