Need help fixing the pulldown menu The names of three states
Need help fixing the pulldown menu: The names of three states should be in a PHP array, and PHP cod should be used to create the drop-down dynamically.
Thanks.
<!DOCTYPE html>
 <html>
 <head>
 <link rel=\"stylesheet\" type=\"text/css\" href=\"l2p4.css\" />
 <title>Creating forms for order</title>
 <script type=\"text/javascript\">
 
 function totalCost ()
 {
 var apricots = parseInt(document.getElementById
(\"Ap\").value);
 var plums = parseInt(document.getElementById
(\"Pl\").value);
 var apples = parseInt(document.getElementById
(\"Ap\").value);
 if(isNaN(apricots))
 alert(\"enter a numeric value in apricots \");
 else
 if(isNaN(plums))
 alert(\"enter a numeric value in plums\");
 else
 if(isNaN(apples))
 alert(\"enter a numeric value in apples\");
 else
 {
 document.forms[\'cal\'].submit();
 }
 }
</script>
 <form name=cal id=cal
action=\"http://weblab.kennesaw.edu/formtest.php\">
 First Name: <input type=\"text\" name=\"fname\" size=\"12\"> <br>
 Last Name: <input type=\"text\" name=\"lname\" size=\"12\"> <br>
 Shipping Address: <input type=\"text\" name=\"Address\" size=\"12\">
 <br>
 <?php
 $state = array(\'New York\', \'Hawaii\',\'California\');
 echo \'<select name=\"state\">\';
 for ($i=0; $i < count ($state); $i++)
 {
 echo \'<option>\'.$ state [$i].\'</option>\';
 }
 echo \'</select>\';
 ?>
 </br>
<table>
 <tr>
 <th>Product Name</th>
 <th>Product Price</th>
 <th>Quantity</th>
 </tr>
 <tr>
 <td>Apricots (7 lb)</td>
 <td>$ 15</td>
 <td><input type=\"text\" name=\"Ap\" id=\"Ap\" value=\"0\" size=\"6\" /></td>
 </tr>
 <tr>
 <td>Plums (7 lb)</td>
 <td>$ 14</td>
 <td><input type=\"text\" name=\"Pl\" id=\"Pl\" value=\"0\" size=\"9\" /></td>
</tr>
 <tr>
 <td>Apples (9 lb)</td>
 <td>$ 8</td>
 <td><input type=\"text\" name=\"Apl\" id=\"Apl\" value=\"0\" size=\"9\" /></td>
 </tr>
 
 </table>
 <h3>CHOOSE YOUR PAYMENT METHOD</h3>
 <label> <input type=\"radio\" name=\"payment\" value=\"visa\" />Visa
 </label> <br> <label> <input type=\"radio\" name=\"payment\"
 value=\"mc\" /> Master Card
 </label> <br> <label> <input type=\"radio\" name=\"payment\"
 value=\"discover\" /> Discover
 </label> <br>
</form>
 <input type=\"button\" value=\"Submit\" onclick=\"totalCost()\"/>
</html>
Solution
In the html content you have mentioned the id as \"Apl\" for the input tag for taking no of apples.
But in the javascript function while trying to get the value of number of apples from input tag you are using tag id as \"Ap\" which retrieves no of apricots value.
Replace php tag with below one :
   <?php
 $state = array(\'New York\', \'Hawaii\',\'California\');
 echo \'<select name=\\\"state\\\">\';
 for ($i=0; $i < count ($state); $i++)
 {
 echo \'<option>\'.$ state [$i].\'</option>\';
 }
 echo \'</select>\';
 ?>


