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

    Dropdown For the Registration Form not to be refreshed on submit and if error present

    I have a form named reg.php and its action is reg.php , i want the selected dropdown value when clicked on submit to remain selected , what i have done so far is given below


    PHP Code:

    <?php
    if( $_POST['registerbtn']){

    $selected_value $_POST['selectID'];
    $query mysql_query("SELECT  linecard_name FROM selection WHERE select_id = '$selected_value'");
    $rows=mysql_fetch_assoc($query); 
    $linecard_name$rows['linecard_name'];
    $sql "SELECT select_id, linecard_name FROM selection " "ORDER BY linecard_name";
    $rs mysql_query($sql);

    while(
    $rownw mysql_fetch_array($rs)){
    if(  
    $rownw['linecard_name'] == $linecard_name)  {
    $options "<option  selected =selected  value=".$rownw['select_id']."> " .$rownw['linecard_name']. " </option> ";
    }

    }
    }


    require(
    "./connect.php");
    $sql "SELECT select_id, linecard_name FROM selection ""ORDER BY linecard_name";
    $rs mysql_query($sql);

    while(
    $rownw mysql_fetch_array($rs)){
     
    $options .= "<option value = ".$rownw['select_id']." > ".$rownw['linecard_name']. " </option> ";

    mysql_close() ;

    $form "<form action='./reg.php'  method='post'> 
    <table>
    <tr>
    <td>  </td>
    <td>  <font color='red'> $errormsg </font> </td> 
    </tr>


    <tr>
    <td> Select  Linecard </td> 
    <td> <Select name='selectID' >  <option value = '0'>  Select  from here </option> $options  </select></td> 

    <tr> 
    <td  > <input type='submit' name='registerbtn' value='Register' />   </td> 
    </tr> 
    </table> 

    echo $form;
    Last edited by Abi89; 06-15-2012 at 05:33 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I don't get the purposes of all those SELECT queries in your code or the use of the involved tables in them. Anyway, you'd need something like
    PHP Code:
    $sql "SELECT select_id, linecard_name FROM selection ""ORDER BY linecard_name";
    $rs mysql_query($sql); 
    ----------------------
    PHP Code:
    echo '<Select name="selectID" >  
    <option value ="0">  Select  from here </option>'
    ;
    while(
    $row=mysql_fetch_assoc($rs)){

    printf("<option value=\"%s\" %s>%s</option"$row['select_id'],
    $row['select_id']==$selected_value'selected="selected"':'',
    $row['linecard_name']);
    }

    echo 
    '</select>'
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The select statements before the register button is clicked is for filling the dropdown from the database with ,
    I just want the selected items to remain selected when the particular selection is done by the user and register button is clicked ,
    in which case my code fills the dropdown again but now with the user selected item as selected but without clearing the previous items filled in the dropdown i.e before the register button is clicked,
    Please help


  •  

    Tags for this Thread

    Posting Permissions

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