How do I populate numeric dropdowns?

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
Wobbly
Forum Newbie
Posts: 4
Joined: Sat Jan 07, 2006 3:21 pm
Location: Victorville, Ca

How do I populate numeric dropdowns?

Post by Wobbly »

Code: Select all

<select name='dropdown' size='1'>
<option value='0'>0</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
Hey guys,

I have several dropdowns that I need to populate with numbers from 1 to 50. Is there a quick way of doing this without having to write a separate option value for each one of them?

Thanks,
Nick
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

No.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

: smacks foobar promptly:
ignore him.

Code: Select all

<option value='0'>0</option>
<option value='1'>1</option>
<option value='2'>2</option>

Code: Select all

for($i=1;$i<51;$i++)
{
   echo "<option value='$i'>$i</option>";
}
that'll give you all the numbers from 1 to 50...next time at least google "looping in php" or something like that,at least try to search ;) either way,you're welcome.enjoy.
Wobbly
Forum Newbie
Posts: 4
Joined: Sat Jan 07, 2006 3:21 pm
Location: Victorville, Ca

Post by Wobbly »

Charles256 wrote: that'll give you all the numbers from 1 to 50...next time at least google "looping in php" or something like that,at least try to search ;) either way,you're welcome.enjoy.
Thanks Charles,

I actually did search; both here and elsewhere... Guess I didn't really know what I was searching for. Anyway, I appreciate your help.

Thanks again,
Nick
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Charles256 wrote:: smacks foobar promptly:
ignore him.
According to his own request:
Is there a quick way of doing this without having to write a separate option value for each one of them?
My answer was correct. You have to write out a separate option-tag for each option. :?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

well..you don't write it out..the loop does..it's a technicallity..: revokes the slap : happy? :-D
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Charles256 wrote:: revokes the slap : happy? :-D
No way. I wanna a cookie! :lol:
Post Reply