sheikhmdirfan Posted April 24, 2009 Share Posted April 24, 2009 I have a page which shows details of a user that can b edited.. these details are filled in the page when it loads. I have a dropdown list containing say name prefixes like Mr, Ms, Mrs, Dr, Prof, Lect, Principal... When the page loads i want the already saved name prefix (in DB) to b selected in the drop down with other options also available. How can i do that.. Any help is welcome... Thanks in advance Link to comment https://forums.phpfreaks.com/topic/155469-selecting-an-option-from-dropdown-on-page-load/ Share on other sites More sharing options...
Yesideez Posted April 24, 2009 Share Posted April 24, 2009 Set an array at the start of your script containing all the titles. $arrTitles=array('Mr','Miss','Mrs','Dr','Prof','Lect','Principal'); Next we need to place some code where you'd place the select/option HTML for the drop-down box. Title: <select name="title"><?php foreach ($arrTitles as $ttl) { echo '<option value="'.$ttl.'"'.($ttl==$strtitle ? ' selected' : '').'>'.$ttl.'</option>'; }?></select> Note: $strtitle will contain the current selected one. Link to comment https://forums.phpfreaks.com/topic/155469-selecting-an-option-from-dropdown-on-page-load/#findComment-818124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.