Mark Stosberg <[EMAIL PROTECTED]> writes: > I'm having trouble with a particular task with SELECT lists that seems > like it should be straight forward. I'm looking for suggestions and > sample code to solve this. > > Here's what I want to do: > > Given the name of the selection list, I want to randomly select one of > the items in the selection list, and return the value that was selected. > > It sounds easy, but HTML::Form seems to be centered around the "OPTION" > tag, rather than the "SELECT" tag,
Why do you have to care? The input-type name does not need to be exposed at all to do what you describe here. I just had to go with one name to make it into a "input-like" object and I went with OPTION. Perhaps I should just make SELECT and alias for the same thing. Here is an example program that demonstrates how to select a random value for the select element. #!/usr/bin/perl -w use HTML::Form; my($form) = HTML::Form->parse(<<"EOT", "http://example.com"); <form> <select name=x> <option> 1 <option> 2 <option> 3 </select> </form> EOT # Find the select element my $x = $form->find_input("x"); # pick a random value my @v = $x->possible_values; my $random_value = $v[rand @v]; $x->value($random_value); # show what we got print $form->click->as_string; __END__ Regards, Gisle