#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    60
    Rep Power
    15
    OK, I am using PHP to process a form. If any required fields were left blank, it shows the form again with the titles of the fields in red letters. For the input boxes, I just put <...value="<?php echo $fieldname?>"> and it works fine. Is there any way to do that for select lists and checkboxes, so the person doesn't have to reselect everything? Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by terium:
    OK, I am using PHP to process a form. If any required fields were left blank, it shows the form again with the titles of the fields in red letters. For the input boxes, I just put <...value="<?php echo $fieldname?>"> and it works fine. Is there any way to do that for select lists and checkboxes, so the person doesn't have to reselect everything? Thanks![/quote]

    Hi,

    For a selectlist you need to have to set the selected option to SELECTED. Compare the value of the option to the selected option, something like:
    <SELECT NAME="mySelect">
    <?
    for($i=0;$i<$numoptions;$i++)
    {
    $mySelect == "optionvalue" ? $selected = " SELECTED": $selected = "";
    print "<OPTION VALUE='optionvalue'$selected>option";
    }
    ?>

    The same kind of solution you can use for checkboxes, but then the selected option should be set to "CHECKED".

    Good luk,

    Peter
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    you could either do something like:

    <OPTION<? if ($listboxvar == "SomethingHere") { echo " selected"; } ?>>Something Here</OPTION>

    for each listbox element. or you could use arrays (which is simpler and easier to modify later).. so something like:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $month_array = array( "January", "February", etc ... );

    while (list(,$current_month) = each($month_array)) {
    if ($current_month == $month_from_form)
    echo "<OPTION selected>$current_month</OPTION>n";
    else
    echo "<OPTION>$current_month</OPTION>n";
    }
    [/code]

    use whatever you want.. those two methods have both worked for me.

    ------------------
    - weeder
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    60
    Rep Power
    15
    Thanks for your help. I had like 20 different values, so I stuck with the arrays. If I have 3 or 4, though, I'd probably do it the other way.

Similar Threads

  1. Value= attribute not sticking for INPUT Type File.
    By mikeyt_3333 in forum HTML Programming
    Replies: 5
    Last Post: May 7th, 2004, 08:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo