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

I want to provide a simple option for a end user to be able to select a data report based on values in a drop down option box, and then have them appear on a simplistic form (later be updated to select and modify) for data verification.

I have the following code:
<form action="http://cgi-bin/Inventory.pl" method="get"> SELECT * FROM 'Inventory' WHERE <select style="font-size:11px;" name="field"> <option value="sernam">Serial Number</option> <option value="asset">Asset Tag</option> <option value="brno">Branch</option> </select> <select name="likeEquals" style="font-size:11px;"> <option value="=">=</option> </select> <input style="font-size:11px;" type="text" name="searchTerm"/> <input style="font-size:11px;" type="submit" name="search" value=" +Search"/> </form>

The above works, but I want to modify it to have the text box to be another option/dropdown box. Similar to the following:

<form action="http://webnm/cgi-bin/Inventory.pl" method="get"> SELECT * FROM 'asset_management' WHERE <select style="font-size:11px;" name="field"> <option value="brno">Branch</option> </select> <select name="likeEquals" style="font-size:11px;"> <option value="=">=</option> </select> <select style="font-size:11px;" name="br"> <option value="HDQTR">Headquarters</option> <option value="CHI">Chicago</option> <option value="DNV">Denver</option> </select> <input style="font-size:11px;" type="submit" name="search" value=" +Search"/> </form>

I want the user to be able to pick out the branch they are looking for data from and after select have that automatically provide the data. How can I make an Option box be treated like a text box? I am pretty new to Perl and figure I have to convert a option value into the text value, but I am not sure how to go about this. Would I use the substitution property to accomplish this or something else? If I am subsituting, then how exactly is the option value stored vs the text value? Any suggestions would be greatly appreciated!

Replies are listed 'Best First'.
Re: How can I change Option values into Text Values
by aquarium (Curate) on Dec 02, 2010 at 22:12 UTC
    the easiest way would be to activate javascript code for the drop-down, and the javascript code alone can populate other fields as necessary. this is all client side, and has nothing to do with perl which runs server side. if you take it a step further you can develop a separate little server side perl script that gives back the values as requested by the javascript code, ala ajax.
    otherwise, with perl being only serverside and running a script to generate CGI that's passed onto web browser client via web server...perl script is either linked to or a form submit etc, and caused full reload of browser window.
    another way to do this is to sort of "fake it". the one perl cgi script always checks CGI parameters at the start of the code, and does different things based on this information. for example called without parameters, it would generate the form. called with some form parameters, it can generate the form with further fields populated. called with all required parameters in the form, it does whatever is needed for the full submit and generates a response. you will need to setup the onchange handler for the drop down, to make it call the same perl cgi script. Nowadays this sort of setup would be considered a bit of a kludge, as although it can and will work, making a selection in the drop-down caused a full reload of browser window and the perl cgi runs and generates the whole screen as needed.
    the hardest line to type correctly is: stty erase ^H