This is a discussion on List select query. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've got a country list which, after selecting and the 'submit' button is clicked, I need for the list ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've got a country list which, after selecting and the 'submit' button
is clicked, I need for the list to re-display the selected list element, the values are for stored database referencing only and not for display. <select name="country"> <option value="<?php echo $country;?>" SELECTED><?php echo $country;?></option> <option Value="AF">Afghanistan</option> <option Value="AL">Albania</option> <option Value="DZ">Algeria</option> ..... <option Value="ZW">Zimbabwe</option> </Select> It's one of those 'mental block' days but what I need is for the list to display the selected element text and not the value so that the user can check their details. Many thanks, Richard. |
|
|||
|
Richard Brooks wrote:
> I've got a country list which, after selecting and the 'submit' button > is clicked, I need for the list to re-display the selected list element, > the values are for stored database referencing only and not for display. > > <...SNIP...> > > It's one of those 'mental block' days but what I need is for the list to > display the selected element text and not the value so that the user > can check their details. > http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1 |
|
|||
|
Oli Filth wrote:
> Richard Brooks wrote: > >>I've got a country list which, after selecting and the 'submit' button >>is clicked, I need for the list to re-display the selected list element, >>the values are for stored database referencing only and not for display. >> >> > > <...SNIP...> > >>It's one of those 'mental block' days but what I need is for the list to >> display the selected element text and not the value so that the user >>can check their details. >> > > > http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1 Read it through many times today and cannot find the named element I'm looking for. A very many thanks for your help! Richard. |
|
|||
|
> I've got a country list which, after selecting and the 'submit' button
> is clicked, I need for the list to re-display the selected list element, > the values are for stored database referencing only and not for display. > > > <select name="country"> > <option value="<?php echo $country;?>" SELECTED><?php echo > $country;?></option> > <option Value="AF">Afghanistan</option> > <option Value="AL">Albania</option> > <option Value="DZ">Algeria</option> > .... > <option Value="ZW">Zimbabwe</option> > </Select> Try this: <select name="country"> <option Value="AF"<?php if ($country=='AF') echo ' SELECTED'; ?>>Afghanistan</option> <option Value="AL"<?php if ($country=='AL') echo ' SELECTED'; ?>>Albania</option> <option Value="DZ"<?php if ($country=='DZ') echo ' SELECTED'; ?>>Algeria</option> .... <option Value="ZW"<?php if ($country=='ZW') echo ' SELECTED'; ?>>Zimbabwe</option> </Select> Better one, which assumes that you have your country names and codes in some array in this format: $countries = array( 'AF' => 'Afghanistan', 'AL' => 'Albania', 'DZ' => 'Algeria', ... 'ZW' => 'Zimbabwe' ); would be: <select name="country"> <?php foreach( $countries as $code => $name ) { printf( "<option value=\"%s\"%s>%s</option>\n", htmlspecialchars( $code ), (($code === $country)?' SELECTED':''), htmlspecialchars( $name ) ); } ?> </select> Hilarion |
|
|||
|
Hilarion wrote:
>> I've got a country list which, after selecting and the 'submit' button >> is clicked, I need for the list to re-display the selected list >> element, the values are for stored database referencing only and not >> for display. [snipped] > > Try this: > > <select name="country"> > <option Value="AF"<?php if ($country=='AF') echo ' SELECTED'; > ?>>Afghanistan</option> > <option Value="AL"<?php if ($country=='AL') echo ' SELECTED'; > ?>>Albania</option> > <option Value="DZ"<?php if ($country=='DZ') echo ' SELECTED'; > ?>>Algeria</option> > .... > <option Value="ZW"<?php if ($country=='ZW') echo ' SELECTED'; > ?>>Zimbabwe</option> > </Select> > > Better one, which assumes that you have your country names and codes in > some array in this format: > > $countries = array( > 'AF' => 'Afghanistan', > 'AL' => 'Albania', > 'DZ' => 'Algeria', > ... > 'ZW' => 'Zimbabwe' > ); > > would be: > > <select name="country"> > <?php > foreach( $countries as $code => $name ) > { > printf( > "<option value=\"%s\"%s>%s</option>\n", > htmlspecialchars( $code ), > (($code === $country)?' SELECTED':''), > htmlspecialchars( $name ) > ); > } > ?> > </select> > > > Hilarion Thanks Hilarion! I've got yet another variation of the above somewhere in my archive tonnage but I had one of those 'elderly' moments and needed a quick answer. Thanks again! Richard. |