On Fri, Aug 22, 2003 at 06:04:11PM -0700, Gisle Aas wrote:
> 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.
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.
How I can find all the possible values and set one on a selection list
that takes multiple inputs?
Mark
####
#!/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
# Find the select element
my $x = $form->find_input("x");
# pick a random value
my @v = $x->possible_values;
use Data::Dumper;
warn Dumper ([EMAIL PROTECTED]);
my $random_value = $v[rand @v];
$x->value($random_value);
# show what we got
print $form->click->as_string;
__END__