How to add values to ListBox?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

How to add values to ListBox?

Post 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..!!!
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: How to add values to ListBox?

Post by novice4eva »

json/ajax anyone of them will work for you.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How to add values to ListBox?

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: How to add values to ListBox?

Post 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.
cboileau
Forum Newbie
Posts: 8
Joined: Sun Nov 02, 2008 8:28 am

Re: How to add values to ListBox?

Post 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.
Post Reply