Mark Stosberg <[EMAIL PROTECTED]> writes: > > > 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. > > Thanks to Gisle's original post, I now have a test case below which > illustrates the issue I'm stuck on. The only difference is that > 'multiple="1"' has been added to the SELECT tag. Now 'possible_values' > returns (undef,1) instead of (1,2,3). I find this really confusing.
What happens in this case is that you get 3 different option-inputs that can each have either the value undef or one of 1, 2 or 3 respectively. It works just like multiple check-boxes that all have the same name. You can pick them up with: $x1 = $from->find_input("x", undef, 1); $x2 = $from->find_input("x", undef, 2); $x3 = $from->find_input("x", undef, 3); > How I can find all the possible values and set one on a selection list > that takes multiple inputs? I would suggest iterate over the inputs in this case and then toggle them indiviually. Like this: #!/usr/bin/perl -w use HTML::Form; my($form) = HTML::Form->parse(<<"EOT", "http://example.com"); <form> <select name="x" multiple="1"> <option> 1 <option> 2 <option> 3 </select> </form> EOT # $form->dump; # Find the options for my $x ($form->inputs) { # only want the "x" stuff next unless $x->name eq "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