Page 1 of 1

How to add values to ListBox?

Posted: Thu Oct 30, 2008 6:58 am
by dilruk83
I have two radio buttons and one Listbox.I wanna do, If i select radio buttonOne then According to that radio button ,listBox values have to be loaded.If i checked other radio button, According to that radio button ,Different listBox values have to be loaded.

Bref:

if select RadioButtonOne
ListBoxOne values shuld be =>> (a,b,c,d,e);

if select RadioButtonTwo
ListBoxOne values shuld be =>> (1,2,3,4,5,6,7,8,9);

rememmber: I have two radio buttons and Only one ListBox

Thank you forum..!!!

Re: How to add values to ListBox?

Posted: Sun Nov 02, 2008 6:19 am
by novice4eva
json/ajax anyone of them will work for you.

Re: How to add values to ListBox?

Posted: Sun Nov 02, 2008 6:22 am
by VladSun
novice4eva wrote:json/ajax anyone of them will work for you.
No need of AJAX in this case. And using jQuery would be an overkill.
Just use the DOM and a little of Javascript.

Re: How to add values to ListBox?

Posted: Sun Nov 02, 2008 9:42 am
by pavanpuligandla
hiya..
no need of ajax or javascript.

u can do that using php itself, firstly hide both the listboxes, then if user clicks radio1, then include list1 else list2

<form action="test.php">
in test.php write code for radio button click(only 1 button shld b clicked at a time)
then
if{radio1(true);
list1}
else{list2}
make sure which list box has to appear if radio1 is clicked. no need to write the condition for radio2, bcoz u r usin only 2 radio buttons..
if u use more than 2 then use switch.

Re: How to add values to ListBox?

Posted: Sun Nov 02, 2008 10:02 am
by cboileau
There are a number of ways to do this depending on what your requirements are. Are you pulling the listbox data from a database or is it predefined data that is hardcoded in the JS? If its hardcoded in the HTML you can use two spans and just have javascript toggle the style display to choose which is showing, if its hardcoded into the JS, you can write a function to fill the listbox data in. If you are looking to pull it from a server, you can use AJAX or a number of other methods to pull the data on the fly.