Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16666

Re: radiobuttons and checkboxes

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: radiobuttons and checkboxes
Date 2012-10-16 17:23 +0000
Organization A noiseless patient Spider
Message-ID <k5k56r$c46$1@dont-email.me> (permalink)
References <m-idnR5KbdOWc-HNnZ2dnUVZ_gadnZ2d@westnet.com.au>

Show all headers | View raw


On Tue, 16 Oct 2012 16:17:53 +1100, Andrew Poulos wrote:

> The user needs to select one or more items. I can't use radio button
> sets because that limits you to only one selected item, but if I use
> checkboxes it means users can have no selected items.
> 
> My options are:
> 
> 1. Use checkboxes and when the user submits the form tell them to make a
> selection if no selection has been made. This seems the obvious choice
> but I'd rather solve the problem with design rather than message boxes.

First of all, you have to code the back end form processing to allow for 
the case that the form gets submitted without any checkboxes selected. 
Your users may not have javascript enabled. Someone might try and attack 
your site using a script that just generates the form as get or post data 
and sends it at the submit url.

Once you have the back end processing sorted (if invalid data is 
submitted, re-present the (partially filled in) form to the user), then 
think about using js to make the front end smarter.

In which case, I think using an onchange handler on all the checkboxes in 
the group to ensure that at least one of them is checked and display an 
alert when the last one is unclicked might be best?

Example at http://www.sined.co.uk/tmp/checkboxes.htm

You could use any suitable container element.

Note that this particular code will still allow the user to submit 
invalid data, as they would with javascript disabled, it just draws their 
attention to the error.

Rgds

Denis McMahon

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

radiobuttons and checkboxes Andrew Poulos <ap_prog@hotmail.com> - 2012-10-16 16:17 +1100
  Re: radiobuttons and checkboxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-16 11:09 +0300
  Re: radiobuttons and checkboxes "Tom de Neef" <tdeneef@qolor.nl> - 2012-10-16 12:27 +0200
    Re: radiobuttons and checkboxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-16 15:20 +0300
    Re: radiobuttons and checkboxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-16 21:02 +0200
  Re: radiobuttons and checkboxes Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-16 04:30 -0700
  Re: radiobuttons and checkboxes SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-10-16 16:44 +0200
    Re: radiobuttons and checkboxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-16 19:32 +0300
      Re: radiobuttons and checkboxes SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-10-17 00:51 +0200
  Re: radiobuttons and checkboxes JJ <jaejunks_at@_googlemail_dot._com> - 2012-10-16 14:58 +0000
  Re: radiobuttons and checkboxes Matt McDonald <matt@fortybelow.ca> - 2012-10-16 12:00 -0400
    Re: radiobuttons and checkboxes "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-16 19:30 +0300
  Re: radiobuttons and checkboxes Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-16 17:23 +0000
  Re: radiobuttons and checkboxes Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-16 17:33 +0000
  Re: radiobuttons and checkboxes Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-16 21:00 +0200

csiph-web