perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wim Kerkhoff <...@nyetwork.org>
Subject Re: Multiple checkboxes with the same name
Date Sat, 19 Apr 2003 00:33:59 GMT
PaweĊ‚ Niewiadomski wrote:

>I am using Embperl 1.3.4 in my website. I have the following problem:
>Suppose I have the following page named checkbox.htm
><html>
>   <body>
>      <form action="checkbox.htm">
>	 1<input type=checkbox name=cb value=1><br>
>	 2<input type=checkbox name=cb value=2><br>
>	 3<input type=checkbox name=cb value=3><br>
>	 4<input type=checkbox name=cb value=4><br>
>	 <input type=submit>
>      </form>
>   </body>
></html>
>Now once I select one of the checkboxes, after I have clicked on submit
>the checkbox stays checked as expected. If, however, I select multiple
>checkboxes they are cleared after the page has reloaded. Is it possible
>to somehow eliminate this problem? Theoretically I could split $fdat{cb}
>into some array and then put an [- if (found_in_array(x)) {$fdat{cb}=x}
>-], where x is the value of the following checkbox before every one of
>them, but that looks pretty messy.
>  
>
Here's the method that I use. Change the name of the checkboxes slightly:

<form action="checkbox.htm">
	b1<input type=checkbox name="cb:1" value=1><br>
	2<input type=checkbox name="cb:2" value=1><br>
	3<input type=checkbox name="cb:3" value=1><br>
	4<input type=checkbox name="cb:4" value=1><br>
	<input type=submit>
</form>

Then, access them like this:

[-
    @checks = grep {/cb:/} keys(%fdat);
    s/cb://g for @checks;
-]

Often checkboxes are used in a table where other columns might contain 
selects, input fields, more checkboxes, and so on. By putting the row 
sequence in the field name, order is preserved. Actually, in my example 
above, the value for the checkboxes is never used. Instead, the value is 
just so that it'll showed up as defined in %fdat.

HTH, YMMV

Wim


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message