-->

populate triple drop down in ajax and php in a for

2019-08-24 01:50发布

问题:

I have managed to populate my three drop down lists in php and ajax. Here is the one part of my code that displays the three dropdown lists:

<?php
echo "<font id=\"categoria\"><select>\n";
echo "<option value='0'>Select the Firm</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria\"><select>\n";
echo "<option value='0'>Select the Claims Hub</option> \n" ;
echo "</select></font>\n";
?>
<?php
echo "<font id=\"subcategoria2\"><select>\n";
echo "<option value='0'>Select the Area</option> \n" ;
echo "</select></font>\n"; 
?> 

My question is: I also have a form on this pages and i want to make the three dropdown lists part of my form in order to post the values into another mysql table. Any suggestions how i can do this? Here is my form part:

<form method="post" align= "right">
<table >
    <tr><td>&nbsp;</td>
    <tr>
        <td>Select the Matter Type: </td>
        <td><?php echo $dropdown; ?></td>
    </tr>
    <tr><td>&nbsp;</td>
    <tr>
         <td style="text-align: left; ">Active  </td>
         <td align="left" >
            <input type="checkbox" name="active" value="1" />
         </td>
    </tr>   
    <tr><td>&nbsp;</td>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" value="Add" align= "right" /></td>
    </tr>

</table>

回答1:

Why not just insert them into the html?

<form method="post" align= "right">
<table >
<tr><td>&nbsp;</td>
<tr>
    <td>Select the Matter Type: </td>
    <td><?php echo $dropdown; ?></td>
</tr>
<tr>
  <td>
    <?php echo "<font id=\"categoria\"><select><option value='0'>Select the Firm</option></select></font>";?>
  </td>
</tr>
<tr><td>&nbsp;</td>
<tr>
     <td style="text-align: left; ">Active  </td>
     <td align="left" >
        <input type="checkbox" name="active" value="1" />
     </td>
</tr>   
<tr><td>&nbsp;</td>
<tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>



标签: php html