开发者

Select box is generated by JavaScript but value is not passed on form submit

I've got a second select box which is created using Javascript when the user selects a value from the first select box. The JS runs a PHP file which queries a MYSQL database for the relevent items depending on the first selection.

The problem I'm having is that the value for the item the user selects in the second box is not passed in the header when the form 开发者_开发知识库is submitted.

Does anyone have any ideas how to get the value and pass it in the header?

Thanks.

This is the PHP for the second select box:

<?php
$cxn = mysqli_connect("localhost", "root", "root", "db") or die("Couldn't       connect");
$choice = $_GET['choice'];
$query = "SELECT ID, Model FROM models WHERE MakeID ='$choice'";
$result = mysqli_query($cxn, $query) or die("Couldn't execute query");

echo "
<select id='model' name='model'>
<option value='0'>Model (any)</option>";
while ($row = $result->fetch_object()) {
echo "
<option value='$row->ID'>$row->Model</option> \n

    ";
}
echo "
 </select>  ";
?>


After creating select field you must append it to your form.

<script>document.getElementById("MyForm").appendChild("select_field_id");</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜