期权的价值

时间:2015-03-03 09:04:05

标签: php jquery ajax select

我无法获得我的选择框的全部价值。

在我的剧本中:

$company = $("#company").val();

在我的HTML中:

<select id='company' name='company'>
<?php
    $con = mysqli_connect("localhost", "root", "", "project") or die("error" . mysql_error($con));
    $qry = "SELECT * FROM company";
    $result = mysqli_query($con, $qry);
    while ($row = mysqli_fetch_array($result))
    {
        echo "<option value=" . $row['company_name'] . ">" . $row['company_name'] . "</option>";
    }
?>
</select>

$company只有第一个字。

2 个答案:

答案 0 :(得分:2)

尝试将单引号置于值

之后
echo"<option value='".$row['company_name']. "'>" .$row['company_name']. "</option>";
                  ^^^                       ^^^

答案 1 :(得分:0)

试试这个。像这样改变你的jquery和选项标记行

    $( "#company option:selected" ).text();

    <select id='company' name='company'>
    <?php
    $con=mysqli_connect("localhost","root","","project") or die("error" . mysql_error($con));
    $qry="SELECT * FROM company";
    $result=mysqli_query($con,$qry);
    while($row=mysqli_fetch_array($result))
    {
     echo"<option value='".$row['company_name']. "'>" .$row['company_name']. "</option>";
    }
      ?>
     </select>