Computer Science Canada

Populating select tag

Author:  Ktomislav [ Sat Jan 09, 2010 7:51 pm ]
Post subject:  Populating select tag

Can you tell me how to populate select tag through for loop?
For example how to add every number form 1 to 10 to select tag (without brute forcing)?

Thanks

Author:  Ktomislav [ Mon Jan 11, 2010 8:13 pm ]
Post subject:  Re: Populating select tag

Well, I'm sorry for double post, but come on guys help me please.

Author:  Zren [ Mon Jan 11, 2010 8:17 pm ]
Post subject:  RE:Populating select tag

code:

<select>
<?php
        for ($i=1;$i<=10;$i++) {
?>
  <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php
        }
?>
</select>

Not generally a PHP/HTML forum but i know some stuff.

Author:  Ktomislav [ Mon Jan 11, 2010 8:20 pm ]
Post subject:  Re: Populating select tag

Thank you very much! Very Happy

edit: Nice trick!

Author:  Zren [ Mon Jan 11, 2010 8:30 pm ]
Post subject:  RE:Populating select tag

No prob. You could do it all in one echo, but it requires a monstrous amount of escape characters.

Thus with PHP, starting and endling blocks don't actually end the script and you can break stuff up like this. It's pretty awesome.

Author:  Ktomislav [ Mon Jan 11, 2010 8:35 pm ]
Post subject:  Re: Populating select tag

I figured it out I know it can be done in one echo, but thanks anyway.
And yes it is pretty awsome because it is so simple, but kinda so powerful. Very Happy


: