Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

return values on select after submit

by bigup401 (Pilgrim)
on May 13, 2019 at 17:01 UTC ( [id://1233715]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: return values on select after submit
by holli (Abbot) on May 13, 2019 at 17:20 UTC
      "...effing..."

      Some hints for the uninitiated:

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: return values on select after submit
by huck (Prior) on May 13, 2019 at 21:21 UTC
    use strict; use warnings; use CGI; my $q = new CGI; my $firstname = $q->param('firstname') || ''; my $lastname = $q->param('surname') || ''; my $cars = $q->param('cars') || ''; #too funny .... https://www.w3schools.com/tags/att_option_selected.asp #$cars='volvo'; print qq|content-type: text/html\n\n|; print qq|<form action="$ENV{SCRIPT_NAME}" method="post">\n|; print qq|<input name="firstname" type="text" value="$firstname"/><hr/> +|; print qq|<input name="surname" type="text" value="$lastname"/><hr/>| +; print "\n"; print qq|<select name="cars" >|,"\n"; my @carlist; push @carlist,["volvo","Volvo"]; push @carlist,["saab","Saab"]; push @carlist,["fiat","Fiat"]; push @carlist,["audi","Audi"]; for my $cl (@carlist) { my $selected= $cars eq $cl->[0]?'selected ':''; print ' ',qq|<option |,$selected,qq|value="|,$cl->[0],qq|">|,$cl->[ +1],qq|</option>|,"\n"; } print qq|</select>|,"\n"; print qq|<input type="submit" name="form_submit" value="go">|;

    way too funny...

Re: return values on select after submit
by poj (Abbot) on May 13, 2019 at 19:59 UTC
    onchange
    <form action="" method="post" name="myform"> <select name="cars" onchange='myform.submit()'> <option value=""></option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </form>
    poj
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: return values on select after submit
by harangzsolt33 (Chaplain) on May 14, 2019 at 16:13 UTC
    TWO mistakes I am noticing in your example with select is that you fail to include a submit button. If you do not include a submit button in the form, then the select itself will never submit itself. The visitor has no way to submit the form.

    You could link the submit action to the onChange event with JavaScript as poj showed you, but that means that even if the user selects the wrong item by accident, your program will submit the selected value. Lol A better way is to include a submit button as huck showed you in his example. So, the user should pick an item from the list and then should press "Submit" to submit the values to the perl script.

    The second mistake is that the <SELECT> tag should not have VALUE="" defined in it! If you want a default item selected already when the user loads the page, you can achieve that by doing this. CORRECT WAY:

    <select name="cars">
    <option value="volvo">Volvo
    <option value="saab" SELECTED>Saab
    <option value="fiat">Fiat
    <option value="audi">Audi
    </select>

    (Shh!! I'm just whispering to your ear: The closing tag for </OPTION> is also totally unnecessary.)

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1233715]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-16 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found