Echoing Selected Option List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Echoing Selected Option List

Post by marnieg »

I have a form that the user fills in. I am also validating that certain fields have been inputted. If the user gets an error I want to echo the fields they already have filled out so they don't have to enter them again. I have this working on all types of input fields except for "Select Option". Here is my code.

Code: Select all

<td><select name='req_std_rec'>
         <option value=''>Select...</option>
         <option value = 'Y' <?php if ($req_std_rec == 'Y'): ?>select='selectetd'<?php endif; ?>>Yes</option>
         <option value = 'N' <?php if ($req_std_rec == 'N'): ?>select='selectetd'<?php endif; ?>>No</option>
      </select></td>
I think I'm close but have tried several versions of this code and still the echoing is not working. Also tried this without the "value =" part but not correct either.
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: Echoing Selected Option List

Post by marnieg »

Fixed the spelling of "selected" but that was not the problem.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Echoing Selected Option List

Post by shawngoldw »

I think it should be selected='selected', no? I just use SELECTED.

Shawn
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: Echoing Selected Option List

Post by marnieg »

Thank you. I knew it was going to be something simple.

This forum is the best. I always find someone who can help and respond quickly and point me in the right direction. :D
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: Echoing Selected Option List

Post by shawngoldw »

No problem
Post Reply