ajax form help

hi all i have this problem:

i have a table organized as




category id

that represent an option list organized in categories; each of this option has a particular point cost eg

id 1

name test

points 1

category_id 1

id 2

name wooo

points 4

category_id 5

now i want to display these options organized by categories, in each category the option will be displayed through radio button in order to make the decision exclusive for the particular category; the user will have 10 points to spend and i want to show via ajax check the remaining points each time the user select or deselect an option.

I though to create a form model in order to manage this form but i can’t figure it out how… can anyone give me a hint?


You could do something like the following in a script

<script type="text/javascript">

   $(function() {

      $(".option-selection").click(function() {

         var numberOfPointsAlreadySpent = 0;

         $(".option-selection").each(function() {

            numberOfPointsAlreadySpent += $.get('/path/to/ajax/action/optionId/' + $(this).val(),function(){},'json');


         $(".option-selection").each(function() {

            if($.get('/path/to/ajax/action/optionId/' + $(this).val(),function(){},'json') > (10-numberOfPointsAlreadySpent)) {



            else {

               if (!$(this).is(':visible')) {








Completely untested, but it should work similarly to what you want.

through radio button

i didn’t quite catch your logic, with radio buttons

  1. user can choose only one option

  2. user can’t clear options in some category

I just assumed she meant checkboxes.

ok, i’ll try to explain better what i mean: i’m trying to make an online game, and i’m coding the user race creation page; in the table shown are contained all the race tratis available.

In the race creation page all of these traits are organized in tabs each of them representing a particular category, eg. race fertility or race government, in order to let the user choose among the available options for that particular category.

That’s why i need to make the choice exclusive for the category and that’s why i use radio buttons: i can’t let the user choose, for example, both imperialism and dictatorship for the kind of government and in the meantime i need to diplay the remainig race points to spend and the race points spent.

I’m trying to figure out how can i organize a form model in order to suit this situation.

Well the form model will help you validate, but I’m not sure you’re going to be able to get the dynamic action that you want within a single request context without coding some javascript by hand or implementing your own widgets.