logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Problem with <SELECT MULTIPLE> in Mech (maybe in HTTP::Form as well?): msg#00020

Subject: Re: Problem with <SELECT MULTIPLE> in Mech (maybe in HTTP::Form as well?)

$option->{'menu'}[1]{'value'} is the value of the option

I got all of the options and walked thru the list till the value matched the one I wanted and then using $option->check worked for me - where $option is the option to be selected.

I "found" the check method in the code for HTML::Form



On Jul 14, 2005, at 12:46 PM, Hal Vaughan wrote:

I'm having problems with a <SELECT MULTIPLE> element in a form, and this seems like it is not just Mech, but a problem with HTTP::Form as well. In short,
this item is a <SELECT MULTIPLE> object and when I first tried to set a
value, I got error messages, so I changed my code to retreive the object and print out the possible values and the value names. It did not print out the values available in the code, so I changed my code to retreive an array of objects and found that this one <SELECT MULTIPLE> object was being treated as a number of OPTION objects. The HTML was not complete (the </OPTION> tags were missing), so I got the page, fixed it with a few regexes, then replaced the HTML, and that didn't fix the problem. After experimenting, I found that once I removed the MULTIPLE keyword from the <SELECT> tag, the item was then seen as one object, and I could use it as expected. I need to know if I'm
doing something wrong, or why a <SELECT MULTIPLE> is not treated as one
<SELECT> object, if this is a bug I need to report, or, if not, how I can select ONE value in a <SELECT MULTIPLE> object. I've included much more
below.

Here's the code for the form object I'm dealing with (the form itself is okay, it seems to be this and a few other <SELECT MULTIPLE> objects that are the
problem:

<SELECT NAME=location  MULTIPLE>
<OPTION SELECTED>
<OPTION Value='1' >East End
<OPTION Value='2' >West End
<OPTION Value='3' >Southside
<OPTION Value='4' >Northside
</SELECT>

When I cleaned it up, it was like this:

<SELECT NAME=location  MULTIPLE>
<OPTION SELECTED Value = ''> </OPTION>
<OPTION Value='1' >East End</OPTION>
<OPTION Value='2' >West End</OPTION>
<OPTION Value='3' >Southside</OPTION>
<OPTION Value='4' >Northside</OPTION>
</SELECT>

This did not make a difference. The only thing that did make a difference was when I removed "MULTIPLE". I changed my code to set the <SELECT> value to get the OPTION object(s), step through each one, and list the possible values
and value names.  Here's the subroutine I used:


sub setselectname {
        my ($form, $option, $name, $val, @obj, @val);
        ($name, $val) = @_;
        if (!checkformelement($name, "option")) {return 0;}
        $form = $mech->current_form();
        @opt = $form->find_input($name, "option");
        print "--------------------------------------------------------\n";
        print "Option name: $name, Count found: $#opt\n";
        foreach (@opt) {
                print "Option:\n";
                @val = $_->possible_values();
                foreach (@val) {
                        print "\tValue: $_\n";
                }
                @val = $_->value_names();
                foreach (@val) {
                        print "\tName: $_\n";
                }
        }
        return 1;
}

Originally, to set the <SELECT> objects value I used:

$mech->select($name, $val);

And once I realized the problem was with the MULTIPLE keyword, I tried:

$mech->select($name, \@val)

Just in case it needed an array (only the first array element was set).

And here's the code it outputs if the MULTIPLE keyword is left in:

--------------------------------------------------------
Option name: locatoin, Count found: 4
Option:
        Value:
        Value:
        Name: off
        Name:
Option:
        Value:
        Value: 1
        Name: off
        Name: East End
Option:
        Value:
        Value: 2
        Name: off
        Name: West End
Option:
        Value:
        Value: 3
        Name: off
        Name: Southside
Option:
        Value:
        Value: 4
        Name: off
        Name: Northside


And here's the code it outputs if the MULTIPLE keyword is left out:

--------------------------------------------------------
Option name: location Count found: 0
Option:
        Value:
        Value: 1
        Value: 2
        Value: 3
        Value: 4
        Name:
        Name: East End
        Name: West End
        Name: Southside
        Name: Northside

So if the MULTIPLE keyword is in, it sees each <OPTION> as a separate item. I
can understand that, but there is no way for me to access the entire
<SELECT>...</SELECT> object as one form element so I can set the value of the <SELECT> object to one of the <OPTION> items. Am I doing something wrong?

I'm under a deadline and everything was going great (I even thought I'd
actually get a weekend off!) until this came up. I need to resolve it, so
any help is greatly appreciated!

Thanks!

Hal





<Prev in Thread] Current Thread [Next in Thread>