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
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>

";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.