show multiple selected values of drop-down after submit if error comes on form

constancerail

New Member
I have this drop-down and user can select multiple options ,how can i keep selected value on form after submit button, if error comes on form\[code\]<th align="right" style="width: 264px"><label id="lcell">*Preferred City for Relocation Work :</label></th> <td> <select onchange="document.getElementById('cand_pref').style.display='none';" name="pcity[]" id="pcity" multiple="multiple" > <?php $pcitylist = array( 'Mizoram' => array( 'Aizawl', 'Champhai', 'Kolasib', 'Lawngtlai', 'Lunglei', 'Mamit', 'Saiha', 'Serchhip' ), 'Nagaland' => array( 'Dimapur', 'Kohima', 'Mokokchung', 'Mon', 'Phek', 'Tuensang', 'Wokha', 'Zunheboto' ), 'Orissa' => array( 'Angul', 'Boudh', 'Bhadrak', 'Bolangir', 'Bargarh', 'Baleswar', 'Cuttack', 'Debagarh', 'Dhenkanal', 'Ganjam', 'Gajapati', 'Jharsuguda', 'Jajapur', 'Jagatsinghpur', 'Khordha', 'Kendujhar', 'Kalahandi', 'Kandhamal', 'Koraput', 'Kendrapara', 'Malkangiri', 'Mayurbhanj', 'Nabarangpur', 'Nuapada', 'Nayagarh', 'Puri', 'Rayagada', 'Sambalpur', 'Subarnapur', 'Sundargarh' ), 'Puducherry' => array( 'Karaikal', 'Mahe', 'Puducherry', 'Yanam' ) ); foreach ($pcitylist as $key => $pcitylist1){ echo '<optgroup label="'.$key.'">'; foreach ($pcitylist1 as $finalCity) { echo '<option value="' . $finalCity . '"' . (isset($_POST['pcity']) && $_POST['pcity'] == $finalCity ? ' selected' : '') . '>' . $finalCity . '</option>'; } echo '</optgroup>';} ?> </select> \[/code\]
 
Back
Top