Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading data into a form 2

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
0
0
US
Hello all,

I have probably a simple question. I'm using a Postgresql database that contains a field where it is either true or false (T or F to be exact). I need to get this information loaded into a form where their input fields are actually drop-down menus with T or F for choices. Can anyone tell me how to load the field data into the form correctly? I know how to put data into a regular textfield, but not a drop-down menu.

Thanks,
Jisoo22
 
the only way I have found to do this is to set that field of the database to a variable - lets say its $tf.

Then in the html of the form object, i would write an if statement like:

<select name=&quot;tf&quot;>
<option value=T <? if($tf==&quot;T&quot;){ print &quot;selected&quot;;} ?>>
T
</option>
<option value=F <? if($tf==&quot;F&quot;){ print &quot;selected&quot;;} ?>>
F
</option>
</select>

hope that helps

Reid Givens
Webdeveloper
 
Another way to use true and false would be radio buttons.
Code:
<input type=&quot;radio&quot; name=&quot;tf&quot; value=&quot;T&quot; <? if($tf==&quot;T&quot;){ print &quot;checked&quot;;} ?>>True
<input type=&quot;radio&quot; name=&quot;tf&quot; value=&quot;F&quot; <? if($tf==&quot;F&quot;){ print &quot;checked&quot;;} ?>>False
[code]
 
Forgive me for being a stickler, but since I strongly hope XHTML catches on some day soon... I'd like to point out that the technically correct standard for those two print statements are actually

print 'selected=&quot;selected&quot;';
and
print 'checked=&quot;checked&quot;';

Either this way or their way works currently... but never hurts to do things by the book.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top