in reply to Re: How to uncheck one checkbox if some other is checked
in thread How to uncheck one checkbox if some other is checked

Hej Anonimous monk(s),

I listened to your advices and found a way to get it done with a lot of help from web of course (it showed then if you search in english you get a lot more hits then when you're searching in swedish ;-) ). It ended up with a code like this :

my $JCHECK=<<END; function CheckBoxes() { if((document.getElementById("P").checked == true) || (document.get +ElementById("F").checked == true) || (document.getElementById("K").ch +ecked == true)) { document.getElementById("Ej").checked = false;} else {document.getElementById("Ej").checked = true;} } END
I changed then header to this
print $qry->start_html(-title => "L\xE4gg till", -lang => 'sv', -bgcolor => "#336699", -script => $JCHECK, #ADDED -style => { -code => ' body,p,b,i,em,dt,li,div,th,td,Tr,u,optio +n,form,dd,dl,sl { font-family: Arial, sans-serif; font-size: 12px; color: #FFFFFF; } a {font-family: Arial, sans-serif; font- +size: 14px; color: #FFFFFF;} h1 {font-family: Arial, sans-serif; font +-size: 30px; color: #FFFFFF;} h2 {font-family: Arial, sans-serif; font +-size: 18px; color: #FFFFFF;} h3 {font-family: Arial, sans-serif; font +-size: 18px; color: #FFFFFF;} ', }, );
And checkboxes are not now checkbox_group (which was very convinient to write), but independant checkboxes. Like this :
print $qry->table ({ Border => 1, Cellpadding => 3, bordercolor =>"#FF +FFFF"}, Tr( td(checkbox(-name => 'P', -id =>'P', -value=> 'Pri', -onClick => + "CheckBoxes()")), td(checkbox(-name => 'F', -id =>'F', -value=> 'For', -onClick => + "CheckBoxes()")), td(checkbox(-name => 'K', -id =>'K', -value=> 'Kap', -onClick => + "CheckBoxes()")), td(checkbox(-name => 'Ej',-id =>'Ej', -value=> 'Ej', -checked => + 'checked', -onClick => "CheckBoxes()")));
and it seems to be working, but only for the first row, så I have to add some iteration somehow but I hope to find it somewhere on the web.

Might be usefull to someone

Replies are listed 'Best First'.
Re^3: How to uncheck one checkbox if some other is checked
by Anonymous Monk on Aug 10, 2012 at 09:31 UTC

    As I mentioned, somewhat more difficult to implement; and I would suggest to drop your approach and settle for something simpler as it will stay that messy.

    The JS function and server-side code I provided are probably good enough, when used together.

    (The easiest algorithm, code-wise, would probably be "mark Ej checkbox somehow, set onclick handlers for all checkboxes to call function that clears other checkboxes if Ej is checked" ... I bet it can be done with no more than a few lines' change to my function, but my javascript-fu is not up for the task today)