HTML Default Option in Select Using PHP Is Not Working -
i'm bug-proofing form allows data editing book entries in database. working except drop-down box. drop-down box automatically populates every unique entry in specific field in database table, , part works perfectly. however, when people click edit book fields populated books information, , wanted drop-down box default correct value book. solution check each value populates drop-down box against actual book's value field , if match, make "selected" value.
it not working. box still populating fine, not defaulting. here code drop-down box.
<span style="margin-left:10px;"> publication type: <select name="publicationtype" > <option value=""></option> <option value="">-------------------------</option> <?php $lpub = ''; if(array_key_exists('publicationtype',$_request)) $lpub = $_request['publicationtype']; $lpubarr = $datasetmanager->getpublicationtype(); foreach($lpubarr $pubstr){ if($pubstr == $bookarr['publicationtype']){ echo '<option '.($lpub==$pubstr?'selected="selected"':'').'>'.$pubstr.'</option>'."\n"; } else{ echo '<option '.($lpub==$pubstr?'':'').'>'.$pubstr.'</option>'."\n"; } } ?> </select> </span> i can provide variables if needed. don't see i'm doing wrong, maybe able catch obvious mistake.
thank you, kai
not sure try this:
<?php $lpub = ''; if( array_key_exists('publicationtype',$_request) ) $lpub = $_request['publicationtype']; $lpubarr = $datasetmanager->getpublicationtype(); foreach($lpubarr $pubstr){ echo '<option '.($lpub==$pubstr?'selected="selected"':'').'>'.$pubstr.'</option>'."\n"; } i removed condition:
f($pubstr == $bookarr['publicationtype']) since didn't $bookarr['publicationtype'] used for, perhaps left there mistake
Comments
Post a Comment