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

Hi All,
I have the following piece of code in an html form:
<input type="radio" name="radio_search" value="All_of_Intranet">All of + Intranet <input type="radio" name="radio_search" value="group_info">This Group
This form gets submited to a perl script that checks what the user clicked on then does somthing based on the value. Here is the way that i'm checking for the value:
my $radio_search=param("radio_search"); if ($radio_search eq "All_of_Lehman") { &search_all(); } elsif ($radio_search eq "test") { &search_group(); } else { print "$radio_search - test<br>"; print "<br><font size=+2><b>Error:</b></font><br>"; print "<br> You need to specified if you want to search the entire + intranet or the current group"; print "<br><br><a href=javascript:history.go(-1)>Back</a>"; exit(); }
Unfortunately, this is not working. I think that i first need to check which of the two elements was checked then grab the value of the checked element. This i can do in javascript, but it would be easier and better if i can do it in Perl. Thanks for your help in advance.
-Kiko

Edit Masem 2001-08-08 - Fixed typo in title

Replies are listed 'Best First'.
Re: How do i chec a radio button in Perl?
by earthboundmisfit (Chaplain) on Aug 08, 2001 at 18:18 UTC
    I believe this isn't working because my $radio_search has not been properly set. Try:
    use CGI; my $q= new CGI; my $radio_search=$q->param("radio_search");
Debugging note
by Agermain (Scribe) on Aug 08, 2001 at 18:19 UTC
    Whenever I get stuck with these kind of problems, I usually just throw a couple print statements into the output. As earthboundmisfit noted, it's probably the way you're assigning the value; if you just put a print $radio_search before your code, you'll see if you're getting the variable correctly.
Re: How do i chec a radio button in Perl?
by Kiko (Scribe) on Aug 08, 2001 at 19:52 UTC
    I was actually printing $radio_search - test, to see if i was getting any value from the form. But as it turns out that wasn't the problem. The problem was that i had an image with a link to the search page, instead of submiting the page. To fix it i removed the link and added onClick="document.form.submit();" to the <\img\> and that worked. Thanks for your help and response.
      The JS method is ok, but what if users have JS turned off? You could also do <INPUT TYPE=IMAGE SRC="..." border=0 ALT="alt text">
        Good point, earthboundmisfit!

        It would be a good idea to use:
        <input type="image" src="..." border="0" alt="submit">


        because personally, I turn JS off many times, since I am not really impressed by everything JS can do... anyhow, it would be a good idea to choose to go this route rather than risk people not being able to use the button.

        Andy