in reply to html checkbox and perl cgi

When you come across problems like these it is a good idea to add some print statements to your script to see what is going on. So if you added some lines like this:
if ($query->param('submit1')){ my $family = $query->param('family'); my $TB = $query->param('TB'); my $LM = $query->param('LM'); my $HS = $query->param('HS'); my $SC = $query->param('SC'); my $AT = $query->param('AT'); print qq|TB: $TB<br>|; print qq|LM: $LM<br>|; print qq|HS: $HS<br>|; print qq|SC: $SC<br>|; print qq|AT: $AT<br>|;
You would see that if any of the checkboxes were ticked they have the value 'on' which is probably not what you want. So the problem is with your HTML - you could change the 'value' attribute of the checkbox to:
<input type="checkbox" name="TB" value="TB">Trypanosoma brucei<br> <input type="checkbox" name="LM" value="LM">Leishmania major<br> <input type="checkbox" name="HS" value="HS">Homo sapiens<br> <input type="checkbox" name="SC" value="SC">Saccharomyces cerevisiae<b +r> <input type="checkbox" name="AT" value="AT">Arabidopsis thaliana<br>
It is also a good idea to check the values from your form before passing the query to the database

Replies are listed 'Best First'.
Re^2: html checkbox and perl cgi
by AdrianJ217 (Novice) on Jan 18, 2014 at 19:03 UTC
    Thank you so much!
      Sorry, could you tell me why the value 'on' is an issue? I thought it is considered on only when it's clicked on. I guess I don't understand the difference between name and value. I thought name is what is passed as the parameter to CGI, not value.
        Parameters have two parts, a name and a value. To get the value of a parameter you query its name: $query->param('name') will return the value. With a checkbox, the parameter will only have a value if it is checked, if it is not checked the value will be empty. The value 'on' is not really an issue, but you want your variable $TB to have the value 'TB' not 'on'.
        Thank you. One of my other html forms needed a dropdown menu which didn't need a value. Why is it only checkboxes need a value and not a dropdown menu? Also, I changed the values but still doesn't work. I will try the print statement, but do I have it print back as an html? I'm sorry to bother you so much. I'm kinda new at this.