Jump to content

sELECTING AN OPTION FROM DROPDOWN ON PAGE LOAD


sheikhmdirfan

Recommended Posts

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

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.

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.