[thelist] Returning form values of inspection

Carl J Meyer cjmeyer at npcc.net
Sat Feb 8 22:49:00 CST 2003


hi Mark,

On Sat, 2003-02-08 at 20:21, Mark Gillingham wrote:
> I did not realize before that SELECT types of form fields would not
> easily return the selected value through a NAME variable like a simple
> TEXT type does. For instance
>
> <INPUT TYPE="text" NAME"firstname" VALUE='<?php echo "$firstname";?>'>
>
> Will return the value assigned to firstname when the form is returned
> subsequent times. I'm having trouble getting a selection to do the
> same. perhaps it cannot. For instance

The way to set a default value for a <select> is through the "selected"
attribute of an <option>, like this:

<select name="binding_type">
<option value="perfect_binding">Perfect Binding</option>
<option value="stapled">Stapled</option>
<option value="hard_cover" selected>Hard Cover</option>
</select>

This will cause "Hard Cover" to be the selected option.  Unfortunately,
this is more difficult to work with in PHP than the default value of a
text input, though it is doable.  You just have to test equality for
each option and print "selected" if equal, something like this for each
option (watch wrap):

<option value="perfect_binding" <?php if($binding_type ===
'perfect_binding') print 'selected'; ?>>Perfect Binding</option>

Hope that helps.

btw, you may want to get used to coding HTML in lowercase: XHTML
requires it, and that's the way the world is headed...

Carl




More information about the thelist mailing list