If condition under dropdown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    If condition under dropdown

    Hi I need some help to learn how to do my dynamic dropdown. Basically on my dropdown I have value Others and when the user select this I want to display another text box beside it. Below is my codes but it didn't work I wonder where it went wrong.


    Dropdown Menu:
    Code:
    echo "
    <tr><td width='100%'><b>Generated By:</b></td>"; 
    $res=mysql_query("select Generated_By  from tblGeneratedBy"); 
    if(mysql_num_rows($res)==0){ 
    echo "there is no data in table.."; 
    } else { 
    echo '
    <td width="100%"><select name="GeneratedBy" id="GeneratedBy" value=\"$GeneratedBy\">'; 
    for($i=0;$i<mysql_num_rows($res);$i++) { 
    $row=mysql_fetch_assoc($res); 
    echo"<option value=\"$row[Generated_By]\" "; 
    if($GeneratedBy==$row[Generated_By]) 
    echo "selected"; 
    echo ">$row[Generated_By]</option>"; 
    }
    if $row[Generated_By]== ('Others') {
     echo "<input type='text' >";  else 
    }echo 
    "</select><br></tr></td>"; 
    }
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    What didn't work? Please be more specific with the problem. Did the whole dropdown box not work or just your input box? Anyway, three things:
    Line 17: you should be self closing your input tags ( <input /> not <input> ).
    Line 17: You have not closed your if( ){ } statement before you have else.
    Line 18: You have closed the previous if statement instead of opening the else statment.

    Regards.

    Comment

    Working...