Jump to content

Setting listbox initial value.


RoninStretch

Recommended Posts

I have a few listboxes that list the values 1-10.

What i'm doing is checking the database and getting a 1-10 result in a variable.

 

I can't seem to use that to set which value is selected on page load.

 

<select name='editbox' value='$edit'>
                <option value='1'>1</option>
                <option value='2'>2</option>
                <option value='3'>3</option>
                <option value='4'>4</option>
                <option value='5'>5</option>
                <option value='6'>6</option>
                <option value='7'>7</option>
                <option value='8'>8</option>
                <option value='9'>9</option>
                <option value='10'>10</option>
              </select>

 

Where $edit = 6 the listbox would load with 6 already selected..

 

Any ideas, i've been searching around for a while now but it's always to do with submitting the listbox data.

Link to comment
https://forums.phpfreaks.com/topic/49986-setting-listbox-initial-value/
Share on other sites

echo "

<select name='editbox' value='$edit'>
                <option ".($edit==1?"selected":"")." value='1'>1</option>
                <option ".($edit==2?"selected":"")." value='2'>2</option>
                <option ".($edit==3?"selected":"")." value='3'>3</option>
etc....
              </select>

";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.