Tutorial :How can I force the user to have at least one selected checkbox, and postback from client-side javascript?



Question:

I have two checkboxes: cb1 and cb2. They are both hooked up to an onClick event which checks if at least one checkbox is clicked. If this is not the case, it throws an alert and reverts the change. If a legal change was made (e.g. cb2 was checked, followed by cb1 being unchecked), the function calls the server function checkChange() which needs the object and eventargs.

I'm having trouble with the following:

  • Reverting the change: how can i find out which checkbox was clicked without adding an extra javascript function for the second checkbox? This has to be a scalable solution as more checkboxes may be added later.
  • How do I call the server function checkChange(). I am aware of "this.Page.GetPostbackEventReference" but I am confused as to the parameters it takes.

Thanks for looking.


Solution:1

To find out which checkbox was clicked, you can add an extra parameter that takes this or some type of checkbox id to your onClick callback.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »