Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a graceful way to select an option in an HTML form (i.e. <option value="xxx" SELECTED>Option Name</option>) after reading the appropriate field in from a database. To clarify - I am pre-populating a form with user information from my database and text fir\elds and tex areas are no problem but when figuring out a graceful way to preselect an option (out of 150+ options in a list) I am at a loss. Please help .... Mike

Replies are listed 'Best First'.
Re: Prepopulate an HTML option List
by PodMaster (Abbot) on Nov 01, 2002 at 08:07 UTC
Re: Prepopulate an HTML option List
by robinacjohnston (Initiate) on Nov 01, 2002 at 12:18 UTC
    I was working with this yesterday and the only reliable solution I could find was to manipulate the HTML using perl or in my case php. You just have to write a script that will build the HTML based upon your list and then have it stick in the SELECTED option when it comes to the desired one. I tried manipulating the DOM to do this also so that I could reselect on the fly, but this just wasn't worth the effort. I dare say it could be done.
Re: Prepopulate an HTML option List
by tjmather (Initiate) on Nov 02, 2002 at 03:52 UTC
    HTML::FillInForm solves this problem of populating the fields in a HTML form, including option tags. (There is a perl module for almost anything on CPAN!) It is pretty easy to use, and doesn't require CGI.pm.