Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    problem with listbox

    hi, I have a php function and html code like that:

    function func_availability($dbc, $day)
    {  $sql    = "SELECT * FROM tblavail";
        $rs = odbc_exec($dbc, $sql);
          exit("Error in SQL");
        { $TID=odbc_result($rs,"ID");
              echo("<option value=\"$TID\"selected=\"selected\">$Tday 
          else if($TID=="4")
              echo("<option value=\"$TID\" selected=\"selected\">$Tday
              echo("<option value=\"$TID\">$Tday</option>");
    html code:-
    <label for="dayvailable" class="required">Day Available:</label><br />
    <select name="day" id="day" tabindex="3" title="day"><?php func_availability($dbc, $_SESSION['day']) ?></select><br />
    and a database table :-
    ID Type
    1 mon
    2 tues
    3 wed
    4 thur
    5 fri
    6 sat
    7 sun

    actullay what i want to do with this function is that i want to display database table data in listbox on form and and I want to set default value of listbox to thursday(4) and when user select another value, submit the form, if an error occurs then listbox should be displayed with the selected value.

    this function is displaying default value in listbox and when i select the value from listbox below thursday and submit the form and if error occurs on the form, it is displayed with the selected value in listbox but when i select value from listbox before thursday and submit the form and if error occurs on the form, it is displayed with the default value in listbox.

    when i view the source code of form after submission i found that 2 values are set selected = selected and what i need is only one should be selected means if user select a value then user's selected value should be set selected otherwise default value should be selected.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    if(isset($_POST[''day]) && $_POST['day']==$TID)
    "<option value=\"$TID\"selected=\"selected\">$Tday 
    else if(
    "<option value=\"$TID\"selected=\"selected\">$Tday 
          else if(
    "<option value=\"$TID\" selected=\"selected\">$Tday
    "<option value=\"$TID\">$Tday</option>"); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts