Forums

Change Labels on Radio Select in Django

I have a form with 20 entry fields, and a radio select (A/B), when the user selects A I want to display Labels A (default), if they press B, I want to display Labels B (for the 20 fields). I can use a Button if that would be easier. I think this can be done with jquery/AJAX, but I'm not sure how to embed it in a django form. Any ideas? cheers.

I think the easiest way to integrate that sort of thing into Django would be to render both sets of labels in your Django view and then use a javascript event on the radio button to show and hide the different label sections as a block.

Thanks Glen...Can you give me an example of what you mean by render both sets of labels in the view? I'm not sure how to do that. And then how would I call the js? call it from the form? How do I link the js to the button/radioselect? thanks for the help.

From your Django view, put all of the labels into the HTML (i.e. both groups of labels). Make sure you can tell the difference between the 2 groups by, for instance, putting them into different divs. Hide one of the divs. In your Javascript, when the user changes your radio button, hide the one group of labels and show the other one.

To call the Javascript, include it into your page as normal and attach an event to the radio button on page load. The callback of the event would do the showing and hiding of the label groups depending on the value of the radio button.