Forum Moderators: coopster

Message Too Old, No Replies

Adding a default in select

default should have 0 action

         

henry0

7:37 pm on Jan 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a form with many fields I use the following () to create a drop box.
Then within the result (for editing purpose) I display the "option selected"
My quandary is that (In editing mode) the drop box options come back in the same order set by the select function, therefore if an user forget to reset to the desired choice the selection is made automatically by inputting the first row of the drop box, therefore changing user’s first choice by defaulting to the first option.
I would like creating a top option that will read default but will not null or update the previous selection made by the user and preserve its first choice, unless the user decide to change it with is working fine.

Thank you

<?php
function query_select()
{ $conn = db_connect();

$sql= "select beginner, intermediate, experienced, very_good,chef from users";
$result = mysql_query($sql,$conn);
echo "<select name=\"cook_rating_post\">";
while(list($beginner, $intermediate, $experienced, $very_good, $chef)=mysql_fetch_array($result)){
$cook_rating_post = stripslashes($cook_rating_post);

echo "<option value=$beginner>$beginner </option><br>";
echo "<option value=$intermediate>$intermediate </option><br>";
echo "<option value=$experienced>$experienced </option><br>";
echo "<option value=$very_good>$very_good </option><br>";
echo "<option value=$chef>$chef</option>";

}
}

?>

henry0

1:11 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can it be done?
thanks

jatar_k

5:23 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



right under your
echo "<select name=\"cook_rating_post\">";
just put in a
<option value="">Please Select</option>

then when it is submitted check to see if it is empty and don't update that column

henry0

5:54 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you
That will do fine

henry0

7:48 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hitting a snag

even if checking for empty
it does not save the previous value
but null it so when coming back in edit the form field is empty

echo "<option value=$please_select>Please Select </option><br>";
if (empty($please_select)) {

jatar_k

8:05 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



then do one of a couple things

use
<option value="none">Please Select</option>

then test for the value of 'none'

- or -

test the value from the db in the loop and echo ' selected' for the value that matches. Then when you update it will retain the old value if not changed.

henry0

8:48 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "selected" works better
Plus I will transform the options in an Array

Edit:
Might need using "serialize and unserialize"
will play with that!
/edit

thanks for the help

Henry