Forum Moderators: coopster

Message Too Old, No Replies

keeping a drop box selection through second visit

first time default OK, then needs to show user's choice

         

henry0

4:10 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello
I have within a form a drop down box that offers category choice to a member
And is part or my CMS available to each member
Problem:
When editing member content the drop down box is set to the first alpha choice
(Here: Agriculture) so if a member is a CPA and if that member does not reselect CPA he/she will be listed in Agriculture when editing his/her content

How can I make that drop Down box getting the member previous choice instead of defaulting back to Agriculture

<<< Sampling of DD box:

<select name="category" Wrap=virtual><option value="ag">AGRICULTURE</option>
<option value="archi">ARCHITECTS</option>
<option value="auct">AUCTIONEERS</option>
>>>
I can show the member where he/she is listed by using:
<<<
<?php print $s[category];?>
>>>
of course to enter that area the member did login through an Authentication system and indeed they both have a unique ID

Thanks

Henry

jetboy_70

4:32 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



If your SELECT box is being generated in PHP, as you loop through the OPTIONs you need to compare each one with $s[category]. If there's a match echo 'selected="selected"' to the end of the line.

If the SELECT box is static, how about using a Javascript function to loop through the OPTIONs (with $s[category] supplied by PHP). When a match is found you can alter the selected OPTION with:

document.myForm.category.selectedIndex = myValue;

henry0

6:10 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks
well, I’ll feel more comfortable in redoing the select box
And converting it from static to PHP
which I should have done first hand :)

edit:
I never needed to build or use a PHP drop down box
any code sampling or tutorial in that range?

coopster

10:55 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There is a snippet in this thread:
When to use array syntax in form elements [webmasterworld.com]

...and another similar discussion here:
Using a form to retrieve data from a MySQL database [webmasterworld.com]

figment88

11:01 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sometimes I do it like jetboy suggests.

Other times, if I'm lazy, or I have a long select list, I set the select using a javascript function and echo the value in php

<script>
document.FORMNAME.SELECTNAME.value="<? echo $form_value;?>";
</script>

henry0

1:06 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks all
I will give a try to a few solutions

regards
Henry