View Full Version : How to load radio elements from an ajax?

4 Mar 2010, 4:15 AM
hi guys
i would like to know how is it possible to load radio elements from an ajax called, a proxy, anyway i need to load element list from php

i don't need to set radio buttons elements seeting them like this

items: [
{boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
{boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
{boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
{boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
{boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}

any help?
i searched on the forum but i wasn't able to find any solutions

thank you

4 Mar 2010, 5:24 AM
check the docs


Mike Robinson
4 Mar 2010, 7:51 AM
Not so fast ... what axelaxel wants to do is to set the items.

Well, one thing that I've begun to do a lot lately is to download source-code from the server by means of e.g. a <script> tag. The tag points to (say...) a php-script which returns computer-generated JavaScript.

Generating such things is much easier than you might think: the JSON encoding of a data structure is JavaScript. Therefore, you simply stick "foobar =" in front of it, and ";" after it, and you're done. Just make sure that you use that script-tag early in the file.

Now, you indeed do have access to parameter values that originated from the server: it's just that they are now "part of your code." JavaScript source-code after all neither knows nor cares "where or how or when" it came to be on the client's computer.


If you find yourself firing an AJAX request "at startup" to get a certain bit of necessary information (as I did...), this does the same thing, in a better way, and it is much more B).


To specifically address your problem now, Axel, "now that you magically have the necessary information right there in a variable (e.g. foobar), you simply need to refer to it in the initialization code of your form. You will construct the contents of the items array dynamically. (I don't think that I would ask the PHP side to ship you "ready-to-use ExtJS data structures." That's a bit lazy ;) ... actually, "more difficult to maintain.")