April 12, 201016 yr Hey everyone. Does anyone know how you can uses checkboxes while making sure that the user can only select one checkbox and not multiple checkboxes. I know that this is achievable with radio buttons but my clients is adamant that they want to have checkboxes. Thanks for any help
April 12, 201016 yr You can use document.getElementsByName('checkboxName') to get all the checkboxes. You can then write a function that unselect each of them except a predefined one, which you can identify using the "this" keyword (unless you're not assigning handlers, but adding event listeners, in which case you'll have to get the window event and use that to identify the target in standards-based browsers and the srcElement in IE), assign a function to each of the checkboxes that passes a reference to itself (if it can) and hope that no-one ever tries using that page without JavaScript enabled and that page performance isn't an issue. Or you call tell your client that he's being an idiot and should just accept that radio buttons are the solution.
Create an account or sign in to comment