# Possible bug in CGI::HtmlExtension::popup\_menu?

**URL:** <https://www.ruby-forum.com/t/possible-bug-in-cgi-popup-menu/146939>\
**Category:** Ruby\
**Created:** [August 26, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/possible-bug-in-cgi-popup-menu/146939 "2008-08-26T23:48:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coffeedryad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@coffeedryad](https://www.ruby-forum.com/u/coffeedryad)\
**Post date:** [August 26, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/possible-bug-in-cgi-popup-menu/146939/1 "2008-08-26T23:48:14Z")

</div>

Hi all,  
I’m trying to use popup\_menu to generate a select box that remembers  
what option it had selected when the page was generated. The relevant  
lines of code are

dura\_list = cgi.popup\_menu(“dura”,  
[“300”, “Five minutes”, (timespan == 300)],  
[“600”, “Ten minutes”, (timespan == 600)],  
[“900”, “Fifteen minutes”, (timespan == 900)])

where timespan has already been set to either the integer value of the  
parameter “dura” or to a default value of 300.

According to the documentation as I understand it, this should generate

Five  
minutesTen minutesFifteen minutes

but instead it generates

Five  
minutesfalsefalse

Looking through the source for popup\_menu on  
[http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html](http://ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html), I found

```
      if value.kind_of?(String)
        option({ "VALUE" => value }){ value }
      else
        if value[value.size - 1] == true
          option({ "VALUE" => value[0], "SELECTED" => true }){
            value[value.size - 2]
          }
        else
          option({ "VALUE" => value[0] }){
            value[value.size - 1]
          }
        end
      end

```

which I think is causing this. Since value[value.size - 1] is false,  
the last else clause is getting triggered and using that as the option  
text. I wasn’t able to find any other reports of this to see if there’s  
a workaround or fix yet.

---

<div class="post-metadata">

**Author:** ![coffeedryad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e99b99/32.png) [@coffeedryad](https://www.ruby-forum.com/u/coffeedryad)\
**Post date:** [August 27, 2008, 12:39am UTC](https://www.ruby-forum.com/t/possible-bug-in-cgi-popup-menu/146939/2 "2008-08-27T00:39:10Z")

</div>

Just as a note, there seems to be a similar issue with explicit “false”  
in checkbox\_group. Are these really bugs, or am I just misunderstanding  
how these methods are meant to be used, or what?
