RoninStretch Posted May 4, 2007 Share Posted May 4, 2007 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 More sharing options...
DaveEverFade Posted May 4, 2007 Share Posted May 4, 2007 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 https://forums.phpfreaks.com/topic/49986-setting-listbox-initial-value/#findComment-245390 Share on other sites More sharing options...
RoninStretch Posted May 4, 2007 Author Share Posted May 4, 2007 Ah thank you very much Link to comment https://forums.phpfreaks.com/topic/49986-setting-listbox-initial-value/#findComment-245397 Share on other sites More sharing options...
DaveEverFade Posted May 4, 2007 Share Posted May 4, 2007 No worries, just noticed tho, you don't need that value='$edit' in there... Link to comment https://forums.phpfreaks.com/topic/49986-setting-listbox-initial-value/#findComment-245402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.